Apache commons dependency not excluded in gradle | Android - android

I have a library project (Janrain:Jump) that uses the org.apache.http.legacy library. When I try to build my project I get the duplicate error like following:
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/codec/StringEncoderComparator.class
So I figured that the org.apache.commons are duplicate entry because Janrain uses it and it's also included in the Android 24 (as an external library). So I tried to remove the commons from the :Jump gradle like:
configurations {
all*.exclude group: 'org.apache.commons'
}
Now, I'd expect that this removes org.apache.commons but I still get the duplicate entry gradle error.
Here is the :Jump gradle file
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
//If building with strict Android 6.0 the following will need to be uncommented
//See: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
//And: http://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-m
useLibrary "org.apache.http.legacy"
defaultConfig {
minSdkVersion 17
targetSdkVersion 24
// replace the below string with your own Google client ID. Make sure this is consistent
// with the values used in openid_appauth_idp_configs.xml
manifestPlaceholders = [
<my values>]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
configurations {
all*.exclude group: 'org.apache.commons'
}
dependencies {
compile 'com.android.support:support-v4:24.2.0'
compile files('libs/org.apache.http.legacy.jar')
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.okhttp:okhttp-apache:2.5.0'
compile 'com.squareup.okio:okio:1.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'net.openid:appauth:0.4.1'
}
allprojects {
repositories {
jcenter()
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
Why is the org.apache.commons not excluded even when I include it in configurations?

Just add this task to your build.gradle then run gradle findDuplicates to find the jars
task findDuplicates {
doLast {
def findMe = 'org/apache/commons/codec/StringEncoderComparator.class'
configurations.runtime.asFileTree.matching {
include '**/*.jar'
}.files.each { File jarFile ->
zipTree(jarFile).visit { FileVisitDetails fvd ->
if (fvd.path == findMe) {
println "Found $findMe in $jarFile.name"
}
}
}
}
}

Related

Databinding fails with NoSuchMethodError

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.

Unable to load class 'com.android.build.gradle.managed.BuildType_Impl

I am trying to do basic ndk implementation using android studio. Now i am failed to sync gradle i think that some configurations are missed from buid.gradle
I getting this error
Error:Unable to load class 'com.android.build.gradle.managed.BuildType_Impl'.
Possible causes for this unexpected error include:Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
My buid.gradle (app)
apply plugin: 'com.android.model.application'
model
{
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "com.example.app"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 23
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
android.ndk {
moduleName = "jniSample"
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile files('libs/httpclient-4.1.3.jar')
compile files('libs/httpcore-4.1.4.jar')
}
}
My build.gradle (project)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle.wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
My problems are solved the solution was putting 'dependencies' outside the model {}
and proGuard Rule changed into
proguardFiles.add(file("proguard-rules.txt"))
instead of
proguardFiles += file('proguard-rules.txt')

Gradle could not find manifest file

I am trying to build a project but I have the following error when I try to build it from command line:
error: Could not find the AndroidManifest.xml file, going up from path [C:\Users\User\Documents\work
space\app\app\app\build\generated\source\apt\debug] found using dummy file []
(max atempts: file:///C:/Users/User/Documents/workspace/app/app/app/build/generated/source/apt/debug/dummy1449680140847.java)
My manifest.xml is under the main foulder in the project structure.
and this is my gradle file:
import com.android.builder.core.DefaultManifestParser
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.ponideapps.recetapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// This is important, it will run lint checks but won't abort build
lintOptions {
abortOnError false
}
task srcZip(type: Zip) {
from projectDir
def manifestParser = new DefaultManifestParser()
def versionName = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
archiveName = "${project.name}-${versionName}.${extension}"
exclude 'build', 'gen', 'bin', '.DS_Store', '.settings', 'local.properties', '.gradle', '*.apk', '.idea', '*.iml', '*.log',
'*/build', "*/gen", "*/bin", '*/*.iml', '*/*.log'
}
assemble.dependsOn srcZip
}
allprojects {
repositories {
mavenCentral()
}
}
android.applicationVariants.all { variant ->
println "Defining task generate${variant.name.capitalize()}Javadoc"
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
//source = files()
//variant.sourceSets.each{ sourceSet ->
// sourceSet.javaDirectories.each{ javaDirectory ->
// //println("adding source dir for javadoc generation: " + javaDirectory)
// source += files(javaDirectory)
// }
//}
//source += files("$buildDir/generated/source/r/" + variant.dirName)
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
//why doesn't this help? This should add the classfiles for the apt & R files
//+ files("$buildDir/intermediates/classes/" + variant.dirName)
//this would allow markdown comments, however, the plugin seems to be broken and always claims it cannot write a file it has just written :(
//options.doclet = 'com.visural.doclets.markdown.standard.Standard'
//options.docletpath = ["./libs/MarkdownDoclet-3.0.jar"]
options.links("http://docs.oracle.com/javase/7/docs/api/", "http://www.joda.org/joda-time/apidocs/");
//this is necessary to create links to the android documentation: the android website does not
//contain the list necessary to create javadoc, the local installation does
options.linksOffline("http://d.android.com/reference", "${android.sdkDirectory}/docs/reference");
exclude '**/BuildConfig.java'
exclude '**/R.java'
options.memberLevel = JavadocMemberLevel.PROTECTED
//this is very much necessary, as the apt files & the R.class would otherwise break the javadoc
failOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
//android annotations
compile files('libs/androidannotations-api-3.0.1.jar')
apt files('libs_annotations/androidannotations-3.0.1.jar')
}
apt {
arguments {
resourcePackageName "com.ponideapps.recetapp"
}
}
Does someone where is the problem?
Thank you very much in advance!
Add this:
apt {
arguments {
resourcePackageName "com.ponideapps.recetapp"
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}

Android multi module with flavors to maven repository

I've been trying to upload a project to a maven repository unsuccessfully. Here is my project structure :
_root
|_ lib1 (aar)
|_ lib2 (aar)
|_ javalib (jar)
lib1 depends on lib2
lib2 depends on javalib
lib1 and lib2 have two flavors (intg and prod)
Problem is when I launch uploadArchives task I have no pom.xml created.
It seems to be due to my flavors (when I remove flavors it works fine), and I can't figure out how to fix this problem.
I really need to work with flavors ... any help is welcome ;)
here are my build.gradle files :
root :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext.versionName = "$System.properties.version"
configure(subprojects) {
apply plugin: 'maven'
group = 'com.test.build'
version = project.versionName
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://localhost:8081/content/repositories/test/") {
authentication(userName: "admin", password: "admin123")
}
}
}
}
}
allprojects {
repositories {
jcenter()
}
}
lib1 :
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
intgCompile project(path: ':lib2', configuration: 'intgRelease')
prodCompile project(path: ':lib2', configuration: 'prodRelease')
}
lib2 :
apply plugin: 'com.android.library'
android {
publishNonDefault true
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName project.versionName
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
prod{}
intg{}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':javalib')
}
javalib :
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I finally found the answer to my issue :
it is NOT possible, but it might be possible to do it one day :
see documentation about that :
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication
I went through this problem with this solution :
// default publication is production which will be published without env name
publishNonDefault true
defaultPublishConfig "productionRelease"
if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
// Publish a main artifact, otherwise the maven pom is not generated
if (android.publishNonDefault && variant.name == android.defaultPublishConfig) {
def bundleTask = tasks["bundle${name.capitalize()}"]
artifacts {
archives(bundleTask.archivePath) {
classifier null
builtBy bundleTask
}
}
}
}
}
I am not satisfied with it but it will do the job for now ...
I spend a lot time to discover why my Android project din't upload my modules to maven. The problem is because I didn't set the defaultPublishConfig inside the android {} brackets in the file build.gradle. The snippet below is how I solved my problem. You need set what flavor you wanna publish to Maven (access build variants tab in the Android Studio to see all your flavors name):
android {
...
defaultConfig {
...
defaultPublishConfig "myFlavorDebug"
}
}

Integration of RoboBinding and retrolambda

I want to use both evant/gradle-retrolambda and RoboBinding/RoboBinding in my android project.
When adding RoboBinding to your project, you can choose to use it with AspectJ using RoboBinding/RoboBinding-aspectj-plugin. However, whenever I turn it on, the lambda expressions in my code produce this compile error:
Error:error at (no source information available)
/mnt/FCEE58DAEE588F30/AndroidstudioProjects/SpeechACall/app/src/main/java/com/voicesense/personality_profiling_dialer/GcmRegistrationHandler.java:1:0::0 The type java.lang.invoke.MethodHandles cannot be resolved. It is indirectly referenced from required .class files
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugAspectJ'.
> The type java.lang.invoke.MethodHandles cannot be resolved. It is indirectly referenced from required .class files
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
This is my build.gradle file
buildscript {
repositories {
mavenCentral()
maven() {
name 'RoboBinding AspectJPlugin Maven Repository'
url "https://github.com/RoboBinding/RoboBinding-aspectj-plugin/raw/master/mavenRepo"
}
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.4.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
classpath 'org.robobinding:aspectj-plugin:0.8.+'
}
}
repositories {
mavenCentral()
}
apply plugin: 'retrolambda'
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'org.robobinding.android-aspectj'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.voicesense.hr_dialer"
minSdkVersion 15
targetSdkVersion 21
}
signingConfigs {
release {
storeFile file("../../../../../../home/amitai/personality-profiling-dialer_key.keystore")
storePassword System.getenv("KSTOREPWD")
keyAlias "alias_name"
keyPassword System.getenv("KEYPWD")
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-project.txt'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda {
jvmArgs '-noverify'
}
ext {
//robobindingVersion = 'latest.integration'
robobindingVersion = '0.8.9'
}
dependencies {
compile files('libs/acra-4.5.0.jar')
compile files('libs/ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar')
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:support-v13:20.0.0'
//compile 'com.netflix.rxjava:rxjava-android:0.20.7'
compile 'io.reactivex:rxandroid:0.24.0'
//compile 'com.googlecode.libphonenumber:geocoder:2.16'
compile 'com.googlecode.libphonenumber:libphonenumber:7.0'
compile ("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
aspectPath ("org.robobinding:robobinding:$robobindingVersion:with-aop-and-dependencies") {
exclude group: 'com.google.guava', module: 'guava'
}
apt "org.robobinding:codegen:$robobindingVersion"
}
And here is a zipped Android Studio project that can be used to reproduce (contains a relevant build.gradle file and a lambda expression that fails to compile).
After some investigation I found out it had to do with AspectJ not being compatible with Java 8.
I believe Java 8 Compatiblity/Update AspectJ · Issue #22 · JakeWharton/hugo and Java 8 not supported · Issue #6 · uPhyca/gradle-android-aspectj-plugin have the same issue. Any suggestions?
I made my own plugin supports aspectj with retrolambda.
GradleAndroidAspectJPlugin
When the project is using retrolambda. You have to recompile the classes using ant iajc after retrolamda compiled.
project.configurations {
aspectjTaskClasspath
aspectsInPath
}
project.repositories {
mavenCentral()
}
def aspectjVersion = '1.8.5';
project.dependencies {
//AspectJ
aspectjTaskClasspath "org.aspectj:aspectjtools:$aspectjVersion"
compile "org.aspectj:aspectjrt:$aspectjVersion"
}
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
def buildTypeName = variant.name.capitalize()
def hasRetrolambda = project.plugins.hasPlugin('me.tatarka.retrolambda')
def copyDir = new File("${project.buildDir.absolutePath}/copyClasses")
if (copyDir.exists()) {
copyDir.deleteDir()
}
copyDir.mkdirs()
def copyClassTask = project.task("copy${buildTypeName}Classes", type: Copy) {
from variant.javaCompile.destinationDir
into copyDir
doLast {
variant.javaCompile.destinationDir.deleteDir()
variant.javaCompile.destinationDir.mkdirs()
}
}
def aspectsInPaths = [];
def aspectsInPathsAbsolute = [];
def aopTask = project.task("compile${buildTypeName}AspectJ") {
doFirst {
project.configurations.aspectsInPath.each {
aspectsInPaths.add(it);
aspectsInPathsAbsolute.add(it.absolutePath);
}
}
doLast {
ant.taskdef(
resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
classpath: project.configurations.aspectjTaskClasspath.asPath
)
ant.iajc(
source: project.android.compileOptions.sourceCompatibility,
target: project.android.compileOptions.targetCompatibility,
fork: "true",
destDir: variant.javaCompile.destinationDir,
bootClasspath: project.android.bootClasspath.join(File.pathSeparator),
inpathDirCopyFilter: "java/**/*.class"
) {
classpath {
variant.javaCompile.classpath.each {
if (!aspectsInPathsAbsolute.contains(it)) {
pathElement(location: it)
}
}
}
inpath {
pathElement(location: copyDir)
aspectsInPaths.each {
if (!it.name.startsWith("aspectjrt")) {
pathElement(location: it)
}
}
}
}
}
}
aopTask.dependsOn(copyClassTask);
def filterPreDexTask = project.task("filter${buildTypeName}PreDex") {
doLast {
def finalPreDexJars = []
project.tasks["preDex${buildTypeName}"].inputFiles.each {
if (it.name.startsWith("aspectjrt") ||
!aspectsInPathsAbsolute.contains(it.absolutePath)) {
finalPreDexJars.add(it)
}
}
project.tasks["preDex${buildTypeName}"].inputFiles = finalPreDexJars
}
}
project.tasks["preDex${buildTypeName}"].dependsOn(filterPreDexTask)
if (hasRetrolambda) {
project.tasks["compileRetrolambda$buildTypeName"].finalizedBy(aopTask)
} else {
project.tasks["compile${buildTypeName}Java"].finalizedBy(aopTask)
}
}
}

Categories

Resources