Databinding fails with NoSuchMethodError - android

After updating to gradle 2.10 every time when I try to assemble debug build of the app I get the NoSuchMethodError exception. Here is the relevant part of the build log:
java.lang.RuntimeException: failure, see logs for details.
cannot generate view binders java.lang.NoSuchMethodError: com.google.common.base.Strings.isNullOrEmpty(Ljava/lang/String;)Z
at android.databinding.tool.util.StringUtils.capitalize(StringUtils.java:57)
at android.databinding.tool.util.ParserHelper.toClassName(ParserHelper.java:23)
at android.databinding.tool.store.ResourceBundle$LayoutFileBundle.getFullBindingClass(ResourceBundle.java:551)
at android.databinding.tool.store.ResourceBundle$LayoutFileBundle.getBindingClassPackage(ResourceBundle.java:541)
at android.databinding.tool.CompilerChef.pushClassesToAnalyzer(CompilerChef.java:124)
at android.databinding.tool.CompilerChef.createChef(CompilerChef.java:73)
at android.databinding.annotationprocessor.ProcessExpressions.writeResourceBundle(ProcessExpressions.java:148)
at android.databinding.annotationprocessor.ProcessExpressions.onHandleStep(ProcessExpressions.java:82)
at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.runStep(ProcessDataBinding.java:154)
at android.databinding.annotationprocessor.ProcessDataBinding$ProcessingStep.access$000(ProcessDataBinding.java:139)
at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:66)
As you can see Method com.google.common.base.Strings.isNullOrEmpty can't be found.
Some specifics
I use Retrolambda 3.2.5 and Java 8. There are no other extra plugins.
Build plugin version: com.android.tools.build:gradle:2.0.0
Build tools version: 23.0.3
OS: OS X
build.gradle looks like this. I altered it slightly to not expose some private stuff, but problem is still there.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'me.tatarka:gradle-retrolambda:3.2.3'
}
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
project.version = '1.0.0'
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += "--set-max-idx-number=50000" // default 60000
}
}
def googleApiKey = "key goes here"
def appVersionCode = 1
def appVersionName = project.version + "." + appVersionCode
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
manifestPlaceholders = [googleApiKey : googleApiKey,
appVersionCode: appVersionCode,
appVersionName: appVersionName]
multiDexEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a"
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"App-${project.version}-${appVersionCode}.apk"
)
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
flavorDimensions "multidex", "leakcanary"
productFlavors {
withLeakCanary {
dimension "leakcanary"
}
withoutLeakCanary {
dimension "leakcanary"
}
develDex {
dimension "multidex"
minSdkVersion 21
targetSdkVersion 23
}
prodDex {
dimension "multidex"
minSdkVersion 15
targetSdkVersion 23
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
lintOptions {
abortOnError false
}
sourceSets {
main {
jniLibs.srcDir 'build/jniLibs'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
dataBinding {
enabled = true
}
}
task copyNativeLibs(type: Copy) {
from(new File(buildDir, 'intermediates/exploded-aar/')) {
include '**/*.so'
exclude '**/lib-detector.so'
}
into new File(buildDir, 'jniLibs')
eachFile { details ->
def pathSplit = details.path.split('/')
details.path = pathSplit[pathSplit.length - 2] + '/' + pathSplit[pathSplit.length - 1]
}
includeEmptyDirs = false
}
tasks.withType(JavaCompile) { javaCompileTask -> javaCompileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-multidex:3.0'
testCompile('org.robolectric:shadows-httpclient:3.0') {
exclude module: 'httpcore'
exclude module: 'commons-codec'
}
testCompile 'org.powermock:powermock-module-junit4:1.5.2'
testCompile 'org.powermock:powermock-api-mockito:1.5.2'
testCompile 'org.roboguice:roboguice:3.0.1'
compile 'com.parse.bolts:bolts-android:1.2.1'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile 'com.google.android.gms:play-services-drive:7.8.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'org.roboguice:roboguice:3.0.1'
provided 'org.roboguice:roboblender:3.0.1'
compile('com.google.inject.extensions:guice-assistedinject:3.0') {
exclude group: 'com.google.inject', module: 'guice'
}
compile 'commons-io:commons-io:2.4'
compile 'commons-lang:commons-lang:2.6'
compile 'com.intellij:annotations:12.0'
compile 'com.google.zxing:core:3.2.1'
compile 'com.google.zxing:android-core:3.2.1'
compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-analytics:7.8.0'
compile 'com.amazon:in-app-purchasing:2.0.1'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0.7'
withLeakCanaryCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
compile 'com.google.android.gms:play-services-ads:7.8.0'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
}
Question
Did anyone else had the same problem? How to fix it? If you need some extra information, please let me know in comments.

Have you tried the new patch on jitpack of simular issue #134 clean-build, there seemed to be something wrong with gradle import ordering you can try it with :
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.github.denis-itskovich:gradle-retrolambda:3.2.3-fix-134'
}

It looks like there is an error with a plugin after upgrading the Android Studio.
If you go in : <Android Studio Dir>/plugins/android/lib/builder-model-x.x.x.jar you may find 2 .jars. Try to delete the old version .jar and keep the new one and also clean and rebuild the project.
if the above does not work try this:
Change the version of Objectify library in the build.gradle file of your backend to 4.0b to 5.0.3 or higher if it exists.
This is may sound irrelevant but objectify 4.0b library has same classes with same package name which are present in appengine sdk like com.google.common.base.Strings.isNullOrEmpty.
when you deploy the app backend the appengine classes are overridden by objectify classes and hence when you try to call some method it is throwing error.
This is solved in objectify 5.0.+
Hope it helps as it helped me solving this issue.

Related

Android aar include jar dependency resources folder

Hello
While developing an Android AAR module, I encounter the following problem
My AAR module has a few jar dependencies, some of them have resources folder with error localized error messages. For some reason when I create the module AAR I noticed that Android build process exclude the resources folder from the jar dependency. The dependencies folder is an essential part since otherwise the error details are not found.
If something could shed light on the issue, I tried to create additional resources folder under main/resources//messages.properties but it didn't help.
Any help will be appreciated
here is my gradle file
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
dependencies {
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
android {
compileSdkVersion 27
buildToolsVersion '26.0.3'
configurations {
javadocDeps
}
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled false
}
}
testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
sourceSets {
androidTest {
...
}
test {
}
}
}
//assembleDebug.dependsOn(copyResDirectoryToClasses)
dependencies {
releaseCompile fileTree(include: ['*.jar'], dir: 'libs')
provided 'com.android.support:appcompat-v7:27.1.1'
provided 'org.jetbrains:annotations:16.0.3'
provided 'com.google.code.findbugs:annotations:3.0.1'
provided 'org.codehaus.sonar-plugins:sonar-ant-task:2.2'
provided 'org.jetbrains:annotations-java5:15.0'
provided 'com.google.android:annotations:4.1.1.4'
provided 'com.squareup.okhttp3:okhttp:3.9.1'
provided 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile files('../sdkSample/lib/qa_utils.jar')
androidTestCompile 'com.google.android:annotations:4.1.1.4'
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
javadocDeps 'com.squareup.okhttp3:okhttp:3.9.1'
javadocDeps 'com.squareup.okhttp:okhttp-urlconnection:3.9.1'
javadocDeps 'com.google.code.findbugs:annotations:3.0.1'
javadocDeps group: 'org.mozilla', name: 'rhino', version: '1.7.7.1'
javadocDeps group: 'org.jetbrains', name: 'annotations', version: '16.0.3'
testCompile files('../sdkSample/lib/qa_utils.jar')
testCompile 'junit:junit:4.12'
testCompile 'org.json:json:20171018'
testCompile 'com.google.android:annotations:4.1.1.4'
testCompile 'org.testng:testng:6.13.1'
testCompile 'com.squareup.okhttp3:okhttp:3.9.1'
testCompile 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
testCompile 'org.robolectric:robolectric:3.8'
androidTestCompile 'com.squareup.okhttp3:okhttp:3.9.1'
androidTestCompile 'com.squareup.okhttp3:okhttp-urlconnection:3.9.1'
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
if(it.project == 'sdkSample') {
it.onlyIf { false }
}
}
}
//ignore all test failures - is done temporary, the final solution is test categorization
project.gradle.taskGraph.whenReady {
-> project.tasks.findAll { it.name =~ /connected.+AndroidTest/ ||
it.name == "testDebugUnitTest" ||
it.name =="testReleaseUnitTest" }.each {
it.ignoreFailures = true
}
}
You need to use api instead of provided. You can find more info from here.
As i know aar cant have transitive dependencies. You may try export fat aar or you can give it a try to
implementation 'your.package:your_artifact:your_version' {transitive = true}
PS: Dont use type #aar
Also known as flatDir, because flatDir dependencies DOES NOT resolve transitives)
implementation 'your.package:your_artifact:your_version#aar' {transitive = true}
On the otherhand, you need to convert your project to maven standards. So that, you need a pom.xml file which points transitive dependencies under dependencies tag.
As you experienced jar files cant have resource files either. If you dont need to resource files, just export jar by executing createFullJarRelease task.
If you have to use .aar, you can add other dependencies that library uses in consumer.

Could not resolve com.commonsware.cwac:camera:0.6.+

I have added tedpicker in my applications from https://github.com/ParkSangGwon/TedPicker
but now for weeks when I try to sync gradle with internet this error shows up
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugApkCopy'.
> Could not resolve com.commonsware.cwac:camera:0.6.+.
Required by: YourApp:app:unspecified > com.github.ParkSangGwon:TedPicker:v1.0.10
> Could not resolve com.commonsware.cwac:camera:0.6.+.
> Failed to list versions for com.commonsware.cwac:camera.
> Unable to load Maven meta-data from https://repo.commonsware.com.s3.amazonaws.com/com/commonsware/cwac/camera/maven-metadata.xml.
> Could not GET https://repo.commonsware.com.s3.amazonaws.com/com/commonsware/cwac/camera/maven-metadata.xml'.
> Host name 'repo.commonsware.com.s3.amazonaws.com' does not match the certificate subject provided by the peer (CN=*.s3.amazonaws.com, O=Amazon.com Inc., L=Seattle, ST=Washington, C=US)
but It works fine if I switch to offline mode in gradle
also this is my app's buid.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
} apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "org.urapp.urapp"
minSdkVersion 19
targetSdkVersion 22
versionCode 2
multiDexEnabled true
versionName "1.1"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
maxProcessCount 4
javaMaxHeapSize "4g"
}
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
maven { url "https://jitpack.io" }
}
android {
useLibrary 'org.apache.http.legacy'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile project(':flexjson-2.1')
compile('org.apache.httpcomponents:httpmime:4.2.6') {
exclude module: 'httpclient'
}
compile project(':Android-AdvancedWebView')
compile project(':flexjson-2.1')
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.6.0'
compile 'com.google.android.gms:play-services-identity:9.6.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'org.apache.httpcomponents:httpclient:4.3.5'
compile 'com.android.support:design:24.2.1'
compile 'net.opacapp:multiline-collapsingtoolbar:1.2.2'
compile 'com.android.support:palette-v7:24.2.1'
compile 'com.github.ParkSangGwon:TedPicker:v1.0.10'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.google.guava:guava:18.0'
compile 'com.github.oliveiradev:image-zoom:0.3.0'
compile 'com.android.support:percent:24.2.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.volley:volley:1.0.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
compile 'com.google.firebase:firebase-crash:9.4.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
}
}
}
apply plugin: 'com.google.gms.google-services'
I have added tedpicker in my applications
I do not recommend using that library, since it has a dependency on a discontinued library (namely, my CWAC-Camera library).
but now for weeks when I try to sync gradle with internet this error shows up
Change url "https://repo.commonsware.com.s3.amazonaws.com" to url "https://s3.amazonaws.com/repo.commonsware.com".
29 March 2022
Just use it like this in Groovy:
implementation 'com.commonsware.cwac.camera:camera:0.6.17'
and in Kotlin:
implementation("com.commonsware.cwac.camera:camera:0.6.17")
and in build.gradle of project:
repositories {
google()
mavenCentral()
maven { url "https://s3.amazonaws.com/repo.commonsware.com"
allowInsecureProtocol = true}
}
https://mvnrepository.com/artifact/com.commonsware.cwac.camera/camera/0.6.17

androidTestCompile not working in Android Studio 2.1.2

I followed the instruction here to add an instrumentation test, but unfortunately Android Studio complains about the classes from the test runner package (com.android.support.test:runner:0.5) or test rules or espresso-core (cannot find symbol). If I change the dependency type from androidTestCompile to compile, the errors disappear. I created an instrumentation run config, and currently that run config is selected.
EDIT:
Here is our Gradle build file:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'realm-android'
apply plugin: 'pmd'
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:2.0.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
classpath 'io.realm:realm-gradle-plugin:1.0.0'
classpath 'io.fabric.tools:gradle:1.21.6'
}
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}
repositories {
jcenter()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' }
maven { url 'https://repo.commonsware.com.s3.amazonaws.com' }
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
// compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:support-v13:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:percent:24.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile "com.mixpanel.android:mixpanel-android:4.8.6"
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.squareup.dagger:dagger:1.2.2'
apt 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('com.facebook.android:facebook-android-sdk:4.13.1') {
exclude module: 'bolts-android'
exclude module: 'bolts-applinks'
exclude module: 'bolts-tasks'
}
compile 'com.facebook.fresco:fresco:0.11.0'
compile 'me.relex:photodraweeview:1.0.0'
compile 'com.jakewharton.rxrelay:rxrelay:1.0.0'
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'
compile 'com.jakewharton.timber:timber:4.0.1'
compile 'javax.annotation:javax.annotation-api:1.2'
compile 'com.cloudinary:cloudinary-android:1.2.2:'
compile 'com.soundcloud.android:android-crop:1.0.1#aar'
compile 'com.rockerhieu.emojicon:library:1.3.3'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'com.trello:rxlifecycle:0.5.0'
compile 'com.trello:rxlifecycle-components:0.5.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-recyclerview-v7:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-support-v4:0.4.0'
compile 'com.jakewharton.rxbinding:rxbinding-design:0.4.0'
compile 'com.github.hotchemi:permissionsdispatcher:2.1.1'
apt 'com.github.hotchemi:permissionsdispatcher-processor:2.1.1'
compile 'net.sourceforge.streamsupport:streamsupport:1.4.3'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'junit:junit:4.12'
}
android {
// General configuration goes here
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
def buildNumber = computeVersionCode()
applicationId 'com.xxx.xxx'
minSdkVersion 19
targetSdkVersion 23
versionCode = buildNumber
versionName '0.2.6'
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
dexOptions {
incremental true
javaMaxHeapSize "6g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
debug {
storeFile rootProject.file('debug.keystore')
storePassword 'xxx'
keyAlias 'xxx'
keyPassword 'xxx'
}
beta {
String password = getKeyStorePassword()
println("password::$password")
if (password) {
storeFile file("beta_release.keystore")
storePassword xxx
keyAlias "xxx"
keyPassword xxx
} else {
println "Environment variable BETA_KEYSTORE_PASSWORD needs to be set"
}
}
}
buildTypes {
localDebug {
minifyEnabled false
debuggable true;
signingConfig signingConfigs.debug
buildConfigField "String", "BACKEND_ADDRESS", "\"http://xxx.xxx.dev/\""
buildConfigField "boolean", "MYVAR2", "false"
buildConfigField "String", "MYVAR3", "\"value\""
resValue "string", "BUILD_TYPE_DISPLAY", "Debug(Local)"
applicationIdSuffix ".debug"
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
lintOptions {
abortOnError true
}
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
universalApk false
}
}
}
task pmd(type: Pmd) {
ruleSetFiles = files("${project.rootDir}/pmd-ruleset.xml")
ignoreFailures = false
ruleSets = []
source 'src'
include '**/*.java'
exclude '**/gen/**'
reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/reports/pmd/pmd.xml"
}
html {
destination "$project.buildDir/reports/pmd/pmd.html"
}
}
}
def computeVersionCode() {
def buildNumber = System.getenv('BUILD_NUMBER')
if (buildNumber == null || buildNumber.isEmpty()) {
println "No BUILD_NUMBER in environment, using 1 as revision"
return 1
}
buildNumber = buildNumber.toInteger()
println "New revision is ${buildNumber}"
return buildNumber
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:24.0.0'
force 'com.android.support:support-v4:24.0.0'
force 'com.android.support:appcompat-v7:24.0.0'
force 'com.android.support:design:24.0.0'
force 'com.android.support:recyclerview-v7:24.0.0'
}
}
I've spent about a day on this myself and finally figured it out. This is an Android Studio feature - termed a feature, but I'd consider it a bug.
To get instrumentation tests working, you need to set your Build Variants to the following:
Test Artifact: Android Instrumentation Tests
Build Variant: debug
See here for more details
I personally think is makes no sense; it's not like you're using androidTestCompileDebug, and running gradle <app_name>:dependencies repeatedly shows pulling in androidTestCompile dependencies, regardless of the build variant. But for some reason, they only resolve in debug.
I hope this helps.

How to include .aar dependency into Android library .aar file

I write some library, which has a portion of UI. Also, this library uses another libraries.
I want to provide release .aar to use this portion of UI in any App.
My library has next dependecies:
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//Http communication, websockets, etc.
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
//Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//Unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
//Other
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
//Reactive programmnig
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
When I built .aar everything is fine, but when I inlude this .aar into another app, I have next problems:
1). ./gradlew clean build
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
/home/user/projects/MainApp/app/build/intermediates/exploded-aar/com.my.sdk/SDK/0.0.1/res/values/values.xml:78:21-29
: No resource found that matches the given name: attr 'fontPath'.
:app:processDebugResources FAILED
Solution is very simple - add to MainApp/app/build.gradle next line:
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
2). When I run MainApp getting this error:
java.lang.NoClassDefFoundError: com.my.sdk.ui.fragment.DialogAppNotInstalledFragment
To solve this I need to add compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0' to MainApp/app/build.gradle.
Same to other dependecies.
In the result I need just copy-paste all my dependecies from my library project to MainApp project.
Is it possible to make library aar contain all necessery dependecies?
build.gradle of library:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
//apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "0.0.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '.readme'
}
lintOptions {
abortOnError false
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//Http communication, websockets, etc.
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
//Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//Unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
//Other
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
//Reactive programmnig
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
// To publish to maven local execute "gradle clean build publishToMavenLocal"
// To publish to nexus execute "gradle clean build publish"
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
artifactId = POM_ARTIFACT_ID
groupId = GROUP
version = VERSION_NAME
// Task androidSourcesJar is provided by gradle-mvn-push.gradle
//artifact androidSourcesJar {
// classifier "sources"
//}
}
}
repositories {
maven {
credentials {
username System.getenv('NEXUS_USER_NAME')
password System.getenv('NEXUS_PASSWORD')
}
url "http://my-nexus-url/"
}
}
}
MainApp/app/build.gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://my-nexus-url/' }
flatDir {
dirs 'libs'
}
}
android {
signingConfigs {
some_config {
keyAlias 'some alias'
keyPassword '741789654uppy'
storeFile file('../my-keystore.jks')
storePassword 'some_password'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.company.app.android"
minSdkVersion 14
targetSdkVersion 23
versionCode 9
versionName "1.0.0"
}
dexOptions {
preDexLibraries = false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.some_config
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile files('libs/StartAppInApp-2.3.1.jar')
// compile files('libs/android-support-v4.jar')
compile files('libs/applovin-sdk-5.2.0.jar')
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
//here is my library!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
compile('com.my.sdk:SDK:0.0.1#aar'){
transitive = true;
exclude(group:'android.support', module: 'support-v4')
}
//***********************************************
//Dependecies from library
//***********************************************
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'org.lucasr.twowayview:twowayview:0.1.4'
compile 'com.android.support:appcompat-v7:23.1.1'
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//************************************************
}
UPDATE
Generated POM file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.sdk</groupId>
<artifactId>SDK</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
</project>
If anybody have the same problem, you may obtain correct answer here
Result build.gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
repositories {
mavenCentral()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "0.0.1"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude '.readme'
}
lintOptions {
abortOnError false
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//Http communication, websockets, etc.
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
//Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//Unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
//Other
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
//Reactive programmnig
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
// To publish to maven local execute "gradle clean build publishToMavenLocal"
// To publish to nexus execute "gradle clean build publish"
android.libraryVariants
publishing {
publications {
maven(MavenPublication) {
artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
artifactId = POM_ARTIFACT_ID
groupId = GROUP
version = VERSION_NAME
pom.withXml {
def depsNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dep ->
if(dep.name != null && dep.group != null && dep.version != null) {
def depNode = depsNode.appendNode('dependency')
depNode.appendNode('groupId', dep.group)
depNode.appendNode('artifactId', dep.name)
depNode.appendNode('version', dep.version)
//optional add scope
//optional add transitive exclusions
}
}
}
}
}
repositories {
maven {
credentials {
username System.getenv('NEXUS_USER_NAME')
password System.getenv('NEXUS_PASSWORD')
}
url "http://nexus-repository-url/"
}
}
}

DOCX4J in Android Studio with Multidex gives duplicate entry error for libraries

I am trying to get all the libraries for docx4j obtained here:
https://stackoverflow.com/a/23710079/1616685
I set up MultiDex successfully, however I get a duplicated entry error:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: org/apache/harmony/awt/internal/nls/Messages.class
as you can see there are a lot of libraries to compile... it is easy to have duplicates, is there a way to avoid from the gradle such errors?
here the gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.example.test_images"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
}
dexOptions {
preDexLibraries = false
// incremental true
javaMaxHeapSize "4g"
incremental true
}
productFlavors {
}
compileOptions {
}
}
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
project.android.dexOptions.preDexLibraries = false
}
}
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = ['--multi-dex']
} else {
dx.additionalParameters += '--multi-dex'
}
}
}
dependencies {
compile ('com.android.support:multidex:1.0.0'){ exclude group: 'java.util.zip' }
compile ('com.android.support:appcompat-v7:22.2.0')
compile ('com.parse.bolts:bolts-android:1.+')
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/ae-awt.jar')
compile files('libs/ae-docx4j-2.8.0-SNAPSHOT.jar')
compile files('libs/ae-jaxb-2.2.5.jar')
compile files('libs/ae-xmlgraphics-commons.jar')
compile files('libs/avalon-framework-api-4.3.1.jar')
compile files('libs/avalon-framework-impl-4.3.1.jar')
compile files('libs/commons-codec-1.3.jar')
compile files('libs/commons-io-1.3.1.jar')
compile files('libs/commons-lang-2.4.jar')
compile files('libs/commons-logging-1.1.1.jar')
compile files('libs/droidText.0.4.jar')
compile files('libs/istack-commons-runtime.jar')
compile files('libs/JAXBNamespacePrefixMapper-2.2.4.jar')
compile files('libs/jaxp-datatype.jar')
compile files('libs/log4j-1.2.15.jar')
compile files('libs/serializer-2.7.1.jar')
compile files('libs/stringtemplate-3.2.1.jar')
compile files('libs/txw2-20110809.jar')
compile files('libs/w3c-css.jar')
// compile 'com.android.support:support-annotations:22.2.0'
// compile 'com.android.support:multidex:1.0.0'
}
https://github.com/plutext/Docx4j4Android4/ is an Android Studio project; it uses Maven shade plugin to repackage org.apache.http

Categories

Resources