I have a very complex project with many libraries that are dependent on each other. I have gone through all of the documentation and videos but nothing is pointing me in the right direction to compile libraries based on flavors. I am confused with the project aspect. If anyone can point me in the right direction to update compile to implementation, that would be great. How do I directly replace configuration: to match the flavors?
Here in an example of two gradles.
vnfmdata
android {
compileSdkVersion build_versions.compile_sdk
buildToolsVersion build_versions.build_tools
defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
publishNonDefault true
flavorDimensions flavor.default
productFlavors {
regular {}
no_meridian {}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
regularCompile project(':vncore')
regularCompile project(path: ':vnlocationservice', configuration: 'meridianDebug')
no_meridianCompile project(':vncore')
no_meridianCompile project(path: ':vnlocationservice', configuration: 'no_meridianDebug')
}
vnlocationservices
android {
compileSdkVersion build_versions.compile_sdk
buildToolsVersion build_versions.build_tools
defaultConfig {
minSdkVersion build_versions.min_sdk
targetSdkVersion build_versions.target_sdk
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
publishNonDefault true
productFlavors {
no_meridian {}
meridian {}
}
buildTypes {
release {
//minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile deps.support.app_compat
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
no_meridianCompile project(':vncore')
meridianCompile project(':vncore')
meridianCompile project(':third:Sas-Android')
//Localytics
meridianCompile deps.support.compat_v26
meridianCompile deps.play.ads
meridianCompile deps.play.location
meridianCompile deps.localytics
///////////////////
meridianCompile 'com.arubanetworks.meridian:meridian:+#aar'
}
edit:
I found that adding a dependencies node into a flavor affected the other flavor. Instead it is better to use <flavor's name>Implementation.
As you stated, you probably went into the Migration Guide resolve matching errors.
vnfmdata
Here the changes are located on the flavors and how the dependencies changed:
android {
...
productFlavors {
regular {
// Forces regular's flavor to point on LocationService meridian's flavor
// because their flavors' name are different
matchingFallbacks = ["meridian"]
}
no_meridian {
// Will automatically point on LocationService no_meridian's flavor
// because they both have the same name
}
}
...
}
dependencies {
// We used the flavors' matching feature
// so gradle knows that if you select regular, you wants the meridian flavor on these 2 projects
implementation project (":vncore")
implementation project (":vnlocationservice")
}
vnlocationservices
Here we see how to declare a dependency which is only use by one flavor.
android {
...
productFlavors {
meridian {}
no_meridian {}
}
...
}
dependencies {
implementation project (":vncore")
meridianImplementation project(':third:Sas-Android')
//Localytics
meridianImplementation deps.support.compat_v26
meridianImplementation deps.play.ads
meridianImplementation deps.play.location
meridianImplementation deps.localytics
///////////////////
meridianImplementation 'com.arubanetworks.meridian:meridian:+#aar'
}
}
Related
I'm developing an android application for my company. The project holds directories: our sdk (library in this case) and a sample app that imports the sdk. When I add product flavors to the sdk (library) the app breaks due to being unable to resolve the dependencies imported from the sdk.
The errors are:
error cannot find symbol class S
error cannot find symbol class SO
error package S does not exist
error method does not override or
implement a method from a supertype
Here is the top-level/project level build.gradle file
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'com.novoda:bintray-release:0.9'
}
}
allprojects {
repositories {
jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is the SDK/Library build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.novoda.bintray-release'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName version
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultPublishConfig "nonlocationVersionRelease"
publishNonDefault true
flavorDimensions "version"
productFlavors {
nonlocation {
dimension "version"
}
location {
dimension "version"
}
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
lintOptions {
abortOnError false
}
}
configurations {
javadocDeps
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
}
publish {
userOrg = '*******'
groupId = 'com.*******.android'
artifactId = '*******'
publishVersion = '2.0.0'
desc = '******* sdk'
website = 'https://github.com/*******/*******-android-public-sdk'
}
and here is the app's build.gradle file:
apply plugin: 'com.android.application'
def computeVersionCode = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = stdout
}
return stdout.toString().trim().toInteger();
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.*******.demo"
minSdkVersion 15
targetSdkVersion 27
versionCode computeVersionCode()
versionName "1.0"
renderscriptTargetApi 20
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
debugConfig {
storeFile file("debug.jks")
storePassword "*******"
keyAlias "com.*******.android"
keyPassword "*******"
}
releaseConfig {
storeFile file("release.jks")
storePassword "*******"
keyAlias "com.*******.android"
keyPassword "*******"
}
}
buildTypes {
debug {
signingConfig signingConfigs.debugConfig
}
release {
signingConfig signingConfigs.releaseConfig
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:preference-v7:27.1.1'
implementation 'com.google.guava:guava:23.0'
implementation 'com.squareup:seismic:1.0.2'
implementation 'net.hockeyapp.android:HockeySDK:3.7.0'
implementation 'jp.wasabeef:blurry:1.0.5'
implementation project(path: ':*******-sdk', configuration:'default')
}
I have been trying to fix this for 4 days and am still stuck. I've tried all of the typical solutions found on stackoverflow. This has been a cascade of problem after problem and this specific one came directly after updating how the sdk is loaded in the app's build.gradle file. I suspect something is wrong with this line where I import the sdk as a dependency (end of app's build.gradle):
implementation project(path: ':*******-sdk', configuration:'default')
but not including 'configuration: 'default'' causes another bug where the app cannot discern which buildVariant of the SDK to use.
How can I get my app up and running while also maintaining the product flavors found in the SDK?
I am looking for a good way to import Room Persistence inside of my Lib to export .aar . I have the following issue that .aar cannot handle dependencies.
When I export my arr and import into another project as lib, it seems as it has no scope to room.
my lib Gradle file :
apply plugin: 'com.android.library'
apply plugin: 'maven'
archivesBaseName = '*****'
android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 5
versionName "1.1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Write out the current schema of Room
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
configurations {
deployerJars
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'android.arch.persistence.room:runtime:1.1.0-beta3'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.0-beta3'
}
Thanks.
I have a requirement to load the different runtime libraries for a apk execution and unit test cases execution.
I am familiar with compile and testCompile scopes but problem is I don't want to load specific compile scope libraries while running the unit tests.
So I came up with some build.gradle like the below. I could able to copy the required jars/aars under the libs folder but these are not considered for class path.
Any thing wrong with this script?
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "example.com.myapplication"
minSdkVersion 21
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
task getDynamicJars(type: Copy) {
delete fileTree("$projectDir/libs/")
if(project.gradle.startParameter.taskNames.contains("test")){
println("Loading Unit test dependencies");
from "$rootDir/runtimeLibs/test/"
into "$projectDir/libs/"
include '**/*.*'
}else{
println("Loading Execute dependencies from:"+"$projectDir/runtimeLibs/execution/"+" To:"+"$projectDir/libs/");
from "$rootDir/runtimeLibs/execution/"
into "$projectDir/libs/"
include '**/*.*'
}
}
dependencies {
println("Loading dependencies");
compile fileTree(dir: "libs", include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.0'
testCompile 'junit:junit:4.12'
}
project.afterEvaluate {
preBuild.dependsOn getDynamicJars
}
How do you like this solution:
def libsFolder
// ..
buildTypes {
release {
// ..
libsFolder = "${releaseLibsDir}"
}
debug {
// ..
libsFolder = "${debugLibsDir}"
}
}
// ..
dependencies {
compile fileTree(dir: "${libsFolder}", include: ['*.jar'])
}
I'm trying to compile my Android app with the new Jack Compiler. Minification with the default proguard android rules fails.
The message I get is
Error:Execution failed for task ':app:compileDebugJavaWithJack'.
> java.io.IOException: com.android.jack.api.v01.ConfigurationException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43
Gradle Console Output
:app:compileDebugJavaWithJack
Jack APIs v01 configuration failed
com.android.jack.api.v01.ConfigurationException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43
at com.android.jack.api.v01.impl.Api01ConfigImpl.getTask(Api01ConfigImpl.java:77)
at com.android.builder.core.AndroidBuilder.convertByteCodeUsingJackApis(AndroidBuilder.java:1914)
at com.android.build.gradle.tasks.JackTask.doMinification(JackTask.java:148)
at com.android.build.gradle.tasks.JackTask.access$000(JackTask.java:73)
at com.android.build.gradle.tasks.JackTask$1.run(JackTask.java:112)
at com.android.builder.tasks.Job.runTask(Job.java:51)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:223)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.jack.IllegalOptionsException: Error while parsing 'C:\Users\Jonathan\AppData\Local\Android\sdk\tools\proguard\proguard-android.txt':43
at com.android.jack.Jack.check(Jack.java:426)
at com.android.jack.api.v01.impl.Api01ConfigImpl.getTask(Api01ConfigImpl.java:71)
... 8 more
Caused by: com.android.jack.antlr.runtime.RecognitionException
at com.android.jack.shrob.proguard.ProguardParser.recoverFromMismatchedToken(ProguardParser.java:138)
at com.android.jack.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:115)
at com.android.jack.shrob.proguard.ProguardParser.arguments(ProguardParser.java:2967)
at com.android.jack.shrob.proguard.ProguardParser.member(ProguardParser.java:2349)
at com.android.jack.shrob.proguard.ProguardParser.members(ProguardParser.java:2174)
at com.android.jack.shrob.proguard.ProguardParser.classSpecification(ProguardParser.java:1863)
at com.android.jack.shrob.proguard.ProguardParser.prog(ProguardParser.java:388)
at com.android.jack.shrob.proguard.GrammarActions.parse(GrammarActions.java:341)
at com.android.jack.Jack.check(Jack.java:423)
... 9 more
proguard-android.txt
This is a standard android SDK file. I've not modified it. The line it doesn't like is in the excerpt below.
# Keep setters in Views so that animations can still work.
# Setters for listeners can still be removed.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(%);
void set*(%, %);
void set*(%, %, %, %);
void set*(%[]); //LINE 43, THROWS ERROR
void set*(**[]);
void set*(!**Listener);
% get*();
%[] get*();
**[] get*();
!**Listener get*();
}
Gradle.config
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24rc2'
defaultConfig {
applicationId "com.company.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
testBuildType "no_proguard"
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
no_proguard {
minifyEnabled false
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:design:23.4.0'
}
What works
The build of course will work if i just exclude proguard-android.txt from the list of proguardFiles but what I don't know is if I'm supposed to do this; does that leave out something important that could break part of my app? Or are all those settings built into Jack's new minifier anyway?
Edit
I tried excluding proguard-android.txt and tested. My app crashed because some part of Guava had been shrunk/obfuscated away.
It works now, I have since updated several libraries and compile tools
Gradle.config
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.test.myapplication"
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testBuildType "no_proguard"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
no_proguard {
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.android.support:support-vector-drawable:25.2.0'
testCompile 'junit:junit:4.12'
}
I tried to run my Android application with Android Studio, and it showed an error saying the following message.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: com/mikepenz/iconics/core/BuildConfig.class
It seems like there's a duplicate library, so that's why it stops running. But I honestly don't know which I should fix with the build.gradle file. So I put my build.gradle file here, and somebody please help me out.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
//wrap with try and catch so the build is working even if the signing stuff is missing
try {
apply from: '../../../signing.gradle'
} catch (ex) {
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.marshall.opensurvey"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
def fileName = file.name.replace(".apk", "-v" + versionName + "-c" + versionCode + ".apk")
output.outputFile = new File(file.parentFile, fileName)
}
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-DEBUG"
try {
signingConfig signingConfigs.debug
} catch (ex) {
}
minifyEnabled false
}
release {
try {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} catch (ex) {
}
zipAlignEnabled true
minifyEnabled false
}
}
lintOptions {
abortOnError false
}
}
repositories() {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v13:23.1.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.squareup.picasso:picasso:2.3.2'
// Google Analytics Library
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services:8.1.0'
// Glide Library
compile 'com.github.bumptech.glide:glide:3.6.1'
// Material Drawer Library by Mike Penz
compile('com.mikepenz:materialdrawer:4.3.8#aar') {
transitive = true
}
// Android Iconics Library by Mike Penz
compile 'com.mikepenz:iconics-core:1.7.9#aar'
compile 'com.mikepenz:google-material-typeface:1.2.0.1#aar'
// Circle image view library
compile 'de.hdodenhof:circleimageview:2.0.0'
// AboutLibraries by Mike Penz
compile('com.mikepenz:aboutlibraries:5.2.5#aar') {
transitive = true
}
}
Your dependencies are conflicting.
duplicate entry: com/mikepenz/iconics/core/BuildConfig.class
This means two of your dependencies contain this class
// Android Iconics Library by Mike Penz
compile 'com.mikepenz:iconics-core:1.7.9#aar'
compile 'com.mikepenz:google-material-typeface:1.2.0.1#aar'
// AboutLibraries by Mike Penz
compile('com.mikepenz:aboutlibraries:5.2.5#aar') {
transitive = true // <- Why?
}
My guess is either the transitive shouldn't be specified or one of the com.mikepenz libs actually contains one of the other libs. For instance if iconics-core is contained in aboutlibraries then you should exclude it by
compile('com.mikepenz:aboutlibraries:5.2.5#aar') {
exclude module: 'com.mikepenz', name: 'iconics-core'
}
An easy way to track down dependency problems by running the gradle task dependencies via gradle dependencies. This shows a nice chart of libs depend on other libs