Reputation: 127
I want to create Android Library with jar file and resources without sources.
Dependency structure :
I can generate jar file by compiling Android Sample Library, but I when I create new workspace with Android Library Sample with generated jar I get errors like this :
Error:Execution failed for task ':sampleAppProject:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
It seems to be cause by duplicated support v4, v7 which are include in my generated jar. When I remove from gradle dependencies support v7 and v4 libraries I get :
Error:(1) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. Error:(1) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. Error:(1) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
So there are missing support resources. How can I solve this?
UPDATE:
After tips from @dawidgdanski I've was able to compile my project. My error changes to finished with non-zero exit value 1 which was caused by duplicated package name I think. I change package name in manifest, but now I get
java.lang.ClassNotFoundException: Didn't find clas "**.android.R$layout" on path: DexPathList[[zip file ...
It seems to by caused by that I change package in manifest and during the compilation R class is not consistent with class included with jar file
From Gradle console :
Upvotes: 3
Views: 3958
Reputation: 2452
Yes, you duplicate the dependencies. If you execute gradle dependencies
in project directory you will see that the support libraries are doubled. In order to prevent such occurrence you need to decide whether or not you really need the support libraries in your Android library. In case you need them you must explicitly tell the end developers that the support libraries should be excluded as well from their apps.
Let's focus on the following snippet:
dependencies {
// App dependencies
compile 'com.android.support:appcompat-v7:21.0.3'
//Library dependency
compile (project(':library')) {
exclude group: 'com.android.support' module: 'appcompat-v7'
}
}
Assuming that your library uses the compatibility library, this is the way in which you exclude unnecessary 'appcompat-v7' dependency.
On the other side, you can just include your library dependency knowing that it comes with appcompat-v7 with the version that meets your demands.
You can see the sample project that I created a while ago. It consists of several modules that collaborate with themselves.
https://github.com/dawidgdanski/BLE-matters
Sometimes you include libraries containing already precompiles dependencies. By executing gradle dependencies
you can see them and exclude them as well. The only thing that you have to recognize is whether the dependency to be excluded is a module or a separate library attached to the parent library that you include.
Exclusion of the precompiled module looks like the following:
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
Whereas, in order to exclude precompiled dependency you specify it this way:
compile (project(':library')) {
exclude group: 'com.android.support' module: 'appcompat-v7'
}
Btw. have you seen similar problems to yours?
Java finished with non-zero exit value 2 - Android Gradle
Your application may have reached 65k methods threshold.
Cheers
Upvotes: 3