java.lang.NoSuchMethodError on compile - java

I'm trying to compile an Android project unsuccessfully. The error message is:
Execution failed for task ':mobile:_compileAppDebug'.
java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
Here are my module's gradle dependencies in which I specify a number of libraries including google Auto:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.auto.value:auto-value:1.0-rc1'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.f2prateek.dart:dart:1.1.0'
}
When I looked at the dependencies I thought I just needed google auto value since that is where the missing method resides but adding the provided does not resolve the issue.
The project gradle file includes the retrolambda plugin
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
Can anyone help me identify which dependencies cause the compile error? Interestingly enough, when I copy the gradle files into an empty project everything runs fine.

Dagger 2.0-SNAPSHOT depends on an Auto SNAPSHOT which had an API change: https://github.com/google/dagger/issues/113
This is perfectly normal and acceptable thing for libraries which are under development. If you cannot tolerate an occasional broken build, do not depend on non-release versions in a manner that can change at any time without warning.

I ran in a similar issue. Some libary I'm using bundles Guava within the jar file.
Thus exluding this specific dependency from the apt configuration fixed the problem:
configurations {
apt.exclude module: 'artifactId-Of-Library'
}

Related

Use provided/compileOnly dependency with Android libraries

For a project, I have this type of structure :
--- app => my Android application
|
\- lib => my Android library
The application use methods from the lib, but I want a build without embedding classes from the lib (since they are also available in a custom AOSP build), which could be done with provided/compileOnly directive for dependencies. The problem is that this directive doesn't work with aar librairies generated by the Android plugin, only with jars.
I found a way to build also jar files by using the custom makeJar task found here :
Build library jar with Gradle
Then in the build.gradle for the application, I can add a dependency like this :
dependencies {
compileOnly fileTree(dir: '../lib/build/outputs/jar', include: ['*.jar'])
...
}
This works fine, but only if the jar has already been generated by a previous build, which means I have to launch ./gradlew build two time to make it work.
I suppose the problem is that unlike regular dependencies (ie compileOnly project(':lib')), the fileTree dependency is evaluated without requesting a build of the sub project and on the first build, no jar file is added to the classpath.
I tried things like preBuild.dependsOn(':lib:makeJar') but without success because it's executed after evaluation.
I can't switch lib to Java plugin because it's Android specific code and I need to build aar for other projects, so is there a better way to use the compileOnly directive with this module ? Or maybe a way to force the lib to be built before the app build.gradle is evaluated ?
add this on your build.gradle(app)
compile fileTree(include: ['*.jar'], dir: 'libs')
or directly compile your jar file as following
compile files('libs/your_filename_in_libs_folder.jar')

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/os/ParcelableCompat.class [duplicate]

I am not sure what this error means.
Execution failed for task ':excelSior:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/util/TimeUtils.class
I am currently using android-support-v4.jar for my libraries
dependencies {
compile project(':addThisSDK')
compile project(':centeredContentButton')
compile project(':googleplayservices_lib')
compile files('libs/adxtag2.4.6.jar')
compile files('libs/android-support-v4.jar')
compile files('libs/aws-android-sdk-1.7.1.1-debug.jar')
compile files('libs/commons-lang-2.6.jar')
compile files('libs/crittercism_v4_4_0_sdkonly.jar')
compile files('libs/dd-plist.jar')
compile files('libs/FiksuAndroidSDK_4.1.1.jar')
compile files('libs/iqengines-sdk-barcode.jar')
compile files('libs/irEventTracker-1.2.jar')
compile files('libs/jolt-core-0.0.7.jar')
compile files('libs/json-utils-0.0.7.jar')
compile files('libs/jsoup-1.7.2.jar')
compile files('libs/kooaba-api-v4-java.jar')
compile 'com.android.support:multidex:1.0.0'
}
Error does not show up during gradle sync. Just when I try to run the application
What could be the problem?
You've probably fixed this by now but just so this doesn't stay unanswered,
Try adding this to your build.gradle:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
You need to check that you have inserted v4 library and compile library? You must not repeat library in your app or your dependence program.
delete the repeat library so that just one V4 remains.
in your app dir build.gradle file
add this command:
android{
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}
it works for me! You can try it!
I also came across this kind issue when re import old eclipse project. It occurred some old dependency as jar file in the project.
just remove
compile fileTree(dir: 'libs', include: '*.jar')
in gradle file
and add dependency in the gradle file.
It works for me ..
In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.
In order to fully resolve the error first of all have a look at Configure Apps with Over 64K Methods (espescially "Configuring Your App for Multidex with Gradle").
Furthermore search for occurences of the class that causes the "duplicate entry" error using ctrl+n in Android Studio. Determine the module and dependency that contains the duplicate and exclude it from build, e.g.:
compile ('org.roboguice:roboguice:2.0') {
exclude module: 'support-v4'
}
I had to try multiple module labels till it worked. Excluding "support-v4" solves issues related to "java.util.zip.ZipException: duplicate entry: android/support/v4/*"
My understanding is that there are duplicate references to the same API (Likely different version numbers). It should be reasonably easy to debug when building from the command line.
Try ./gradlew yourBuildVariantName --debug from the command line.
The offending item will be the first failure. An example might look like:
14:32:29.171 [INFO] [org.gradle.api.Task] INPUT: /Users/mydir/Documents/androidApp/BaseApp/build/intermediates/exploded-aar/theOffendingAAR/libs/google-play-services.jar
14:32:29.171 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':BaseApp:packageAllyourBuildVariantNameClassesForMultiDex'
14:32:29.172 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :BaseApp:packageAllyourBuildVariantNameClassesForMultiDex FAILED'
In the case above, the aar file that I'd included in my libs directory (theOffendingAAR) included the Google Play Services jar (yes the whole thing. yes I know.) file whilst my BaseApp build file utilised location services:
compile 'com.google.android.gms:play-services-location:6.5.87'
You can safely remove the offending item from your build file(s), clean and rebuild (repeat if necessary).
check your dependencies versions, you must have compatible versions put attention specially to com.google packages, must have same version like:
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-maps:8.3.0'
Both are 8.3.0, if you have another version compilation will throw that exception.
Simple Remove Your Jar file from dependencies gardle.project as v7
and run your project
For Expose.class Error i.e
java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
use the below code
configurations {
all*.exclude module: 'gson'
}
find out the lib depends on the support v4, and exclude it.
code in build.gradle is like this:
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
// http://stackoverflow.com/a/30931887/5210
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
In my situation, the lib 'espresso' has a jar called support-v4 and in my project 'app' have the same support-v4, exclude the support-v4 when import espresso.
PS: it seems compile project can not work with the exclude
This is because you have added a library and given its dependency on a module more than once.
In my case, I had added a library as a module and as a gradle dependency both.
Removing one source of adding library (I removed gradle dependency) solved my problem.
For Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug' com.android.build.api.transform.TransformException java.util.zip.ZipException duplicate entry com/google/gson/annotations/Expose.class
Here is what I did:
1) Delete the gson-2.5.jar file.
2) configurations { all*.exclude module: 'gson-2.5' }
I have faced this issue as i have manually copied the jar in libs as well as mentioned the dependency in gradle file. You also check in your project structure, whether the same jar file is copied in any other folder like libs or in project folder.
I had the same problem after upgrading the android SDK. I was able to run the application in the buildToolsVersion '23.0.1', I got the same error when I changed to buildToolsVersion '24.0.3'
I resolved the problem by updating my java version from 1.7 to 1.8 with compileSdkVersion 24
This problem cost me one whole day. I finally downgraded the firebase-ui library version from 2.0.0 to 1.2.0 and added the following code inside Project level build.gradle file:
allprojects {
repositories {
jcenter()
// Add the following code to your project level build.gradle
maven {
url 'https://maven.fabric.io/public'
}
}
}
I also have the issue because of i have compile 'com.android.support:appcompat-v7:24.0.0-alpha1' but i added recyclerview liberary compile 'com.android.support:recyclerview-v7:24.0.2'..i changed the version as same as compat like (24.0.2 intead of 24.0.0).
i got the answer..may be it will help for someone.
In my case the mentioned "duplicate entry" error arised after settingmultiDexEnable=true in the build.gradle.
and exact error which i was getting was below :
Error:Execution failed for task
':android:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
com/google/android/gms/internal/zzqx.class
So first thing I search for class which causes "duplicate entry" error using ctrl+n in Android Studio and searched for com/google/android/gms/internal/zzqx.class and then it was showing 2 entries for gms class with one version 8.4.0 and 1 with version 11.6.0 .
To fix it i made both to use 11.6.0 and it was fixed example
earlier
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:8.4.0"
compile "com.google.android.gms:play-services-ads:11.6.0"
After
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:11.6.0"
compile "com.google.android.gms:play-services-ads:11.6.0"
Rebuilding Fixed .
In my case exact error was below
':android:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzqx.class
I was using another version of google apis i.e. in one modules gradle file
if (!project.hasProperty('gms_library_version')) {
ext.gms_library_version = '8.6.0'
}
however in other modules version 11.6.0 as below
compile "com.google.android.gms:play-services-ads:11.6.0"
compile "com.google.android.gms:play-services-games:11.6.0"
compile "com.google.android.gms:play-services-auth:11.6.0"
However to find this i did a ctrl + n in android studio and entered class name zzqx.class and then it displayed 2 jar files being pulled for this class and then i understood that somewhere i am using version 8.6.0 . On changing 8.6.0 to 11.6.0 and rebuilding the project the issue was fixed .
Hope this helps .
More on this here
https://www.versionpb.com/tutorials/step-step-tutorials-libgdx-basic-setup-libgdx/implementing-google-play-services-leaderboards-in-libgdx/
For me something similar happened when I had accidently added
apply plugin: 'kotlin-android'
to my android library module. Removing the line fixes the issue.
I tried all the above solutions but not working for me. I tried update libraries by goto project structure > app. And it works for me! Hope this answer helpful to someone.
Try this:
android {
configurations {
all*.exclude module: 'PhotoView' //去除重复依赖库
}
}

build.gradle dependency on gitlab (local server)

Note: I am not very familiar with gradle
Several projects I've worked on with gradle have a dependencies section such as the following where I used the Sugar ORM:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.github.satyan:sugar:1.3'
}
I can compile the Sugar ORM project using:
'com.github.satyan:sugar:1.3'
I have a local server hosting a small library on GitLab which I want to include in my next gradle project.
I want to be able to do the following in my dependencies section for my new project:
dependencies {
compile 'git.devstuff.com:?:?'
}
http://git.devstuff.com/admin/broadcast_lib.git (local server) is the where my git project is, but I don't know how to fill in the question marks in the above code snippet.
The end result I would like is to include the library in a future project via the following in my build.gradle file:
dependencies {
compile 'git.devstuff.com:broadcast_lib:1.0'
}
I'll update the question if I'm lacking information.

How to convert a non-gradle JUnit project (that uses Hibernate and EntityManager) to a gradle Junit project and keep it working

I have a JPA/Hibernate project that implements a number of repository interfaces (I use DDD) and I have another project that tests the first one, by using JUnit 4. My IDE is Eclipse Luna. I learned later that I could made a single project with both runtime and testing code, but at this moment, I have them separated in those two projects.
Everything works perfectly so far.
Now, I decided to convert my test project in a Gradle project. After converting, I created this build.gradle file
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
repositories {
mavenLocal()
mavenCentral()
}
jar {
baseName = 'dominio.hibernate.tests'
version = '0.1.0'
}
dependencies {
compile 'junit:junit:4.11'
compile 'org.hamcrest:hamcrest-all:1.3'
runtime fileTree(dir: '../dominio/build/libs', include: '*.jar')
compile fileTree(dir: '../dominio/build/libs', include: '*.jar')
runtime fileTree(dir: '../dominio.hibernate/build/libs', include: '*.jar')
compile fileTree(dir: '../dominio.hibernate/build/libs', include: '*.jar')
compile 'postgresql:postgresql:9.0-801.jdbc4'
compile 'org.hibernate:hibernate-core:4.3.6.Final'
compile 'org.hibernate:hibernate-c3p0:4.1.0.Final'
compile "javax.enterprise:cdi-api:1.0-SP1"
compile "javax.servlet:servlet-api:2.5"
runtime "org.jboss.weld:weld-core:1.0.1-SP1"
compile project(':Dominio')
compile project(':DominioHibernate')
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
The compile works perfectly, but when I run the tests, iether in Eclipse or by Gradle, I have the folowing exception
javax.persistence.PersistenceException: No Persistence provider for EntityManager named unidades
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at dominio.hibernate.tests.HibernateUnidadeOrganizacionalRepositoryTests.setUp(HibernateUnidadeOrganizacionalRepositoryTests.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
... the rest of the stack
I stress that nothing changed in the Java code and it ran perfectly before Gradle came into the scene.
So, it appears that after converting the project to a Gradle one, persistence.xml is not being reachable anymore during the JUnit run, and I can't get the EntityManager instance I need to perform the tests.
I browsed a large number of posts about problems relating JUnit, resource files and Gradle, but no one of them could give me an idea about how to fix the problem.
Any ideas? Thanks in advance!
To successfully run tests that make use of Hibernate, Hibernate resources and related code have to placed in the same output directory:
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
This is only a problem for tests, as they have the output directories on their class path, rather than the Jar/War. (This avoids the need to build a Jar/War for running tests.)
Thanks to Peter Niederwiser answer and comments, this post in StackOverflow and some reading on Gradle documentation about Java plugin I was able to figure it out what was wrong and fix it. Detais below:
Peter suggestions on updating the resourceDir for both main and test source sets were done (see Peter's answer and his comments)
There was a Hibernate package missing for runtime environment; I updated the dependency block to add it:
dependencies {
...
compile 'org.hibernate:hibernate-entitymanager:4.3.6.Final'
runtime 'org.hibernate:hibernate-entitymanager:4.3.6.Final'
...
}
Only this two steps combined fixed my problem. The META-INF folder was copied to the right place and the (now present) Hibernate package was there to handle persistence.xml in order to create the EntityManager instance my testing code needed.

Different dependencies for debug and release in gradle and Android Studio

I have an Android project, that depends on pure Java project. Both of them depend on another Java library, also in my multiproject gradle set in Android Studio. I have two versions of that library and want both Android and Java projects to depend on one of them in debug mode, and another - in release.
Is it possible for Android project? For pure Java project? How?
Build Types (debug, release, or custom) can have their own dependencies.
To specify a dependency specific to a build type, do the following:
dependencies {
debugCompile "mydebugdependency"
releaseCompile "myreleasedependency"
}
If your java project and android project are both using gradle, you can do the above in both of their build.gradle files.
My buildDebug dependency was also getting ignored. My setup is the app module and a library module, and I have the need to propagate the build type from the app to the library modules, i.e., when I compile the debug type on the app I want to get the library debug type too.
As mentioned, I tried having a specific dependency for each build type on the app gradle file, but to no avail:
buildTypes {
debug {
debuggable true
applicationIdSuffix ".debug"
dependencies {
debugCompile project(":library")
}
}
}
Ultimately what did the trick for me was this: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication
So, now the library dependency is managed (as usual) in the global dependencies scope in the app gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
releaseCompile project(path: ':library', configuration: 'release')
debugCompile project(path: ':library', configuration: 'debug')
}
and had to add this to the library's gradle build file:
android {
publishNonDefault true
}
This publishes all of the dependencies' build types. Note that if it takes a lot of time to compile your dependency, this solution might not be right for you.
You are able to do this using next pattern
build_variant_name dependency_configurations "dependency"
build_variant_name dependency_configurations project(path: ':libName', configuration: 'build_variant_name of libName')
For example
dependencies {
FreeDebugImplementation "dependency"
PaidReleaseApi project(path: ':libName', configuration: 'release')
}
You can read more about
build variants - https://developer.android.com/studio/build/build-variants
dependency configurations - https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#new_configurations

Categories

Resources