-
Notifications
You must be signed in to change notification settings - Fork 27
AndroidGradlePreprocessing
Igor Maznitsa edited this page Apr 20, 2019
·
13 revisions
if you want add some preprocessing into Android project (under Gradle build system) then you should add some prefix into your build script
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.igormaznitsa:jcp:7.0.1'
}
}
apply plugin: 'com.igormaznitsa.jcp'
and postfix
preprocessSettings {
def targetFolder = 'build/preprocessed/java'
target = file(targetFolder)
sources = ['src/main/java']
android.sourceSets.main.java.srcDirs = [targetFolder]
}
preBuild.dependsOn preprocess
I made experiments with Android project created with Android Plug-in under Intellij IDEA and played with build.gradle
on App module level which is created by the plug-in. So total build.gradle in my case looked like
// section for preprocessor
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.igormaznitsa:jcp:7.0.1'
}
}
apply plugin: 'com.igormaznitsa.jcp'
// end section for preprocessor
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "android.it.igormaznitsa.com.jcpandroid"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
// preprocessor settings
preprocessSettings {
def targetFolder = 'build/preprocessed/java'
target = file(targetFolder)
sources = ['src/main/java']
android.sourceSets.main.java.srcDirs = [targetFolder]
}
preBuild.dependsOn preprocess