Here is a test project: click
I have a test project Gradle Android with three modules: app, library_a, library_b. appdepends on library_a, then library_adepends on library_b:
build.gradle (application)
dependencies {
...
compile (project(":library_a")){
transitive = false;
}
}
build.gradle (library_a)
dependencies {
...
compile (project(":library_b")){
transitive = false;
}
}
Please note that I install transitive = falsebecause I do not want classes from to library_bbe accessible fromapp
Each module has only one class, the code is pretty simple:
applications:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
ClassA classA = new ClassA();
classA.doSomething();
}
}
library_a:
public class ClassA
{
public void doSomething(){
Log.i("Test", "Done A!");
ClassB classB = new ClassB();
classB.doSomething();
}
}
library_b:
public class ClassB
{
public void doSomething(){
Log.i("Test", "Done B!");
}
}
Well, here is the problem: I am building my project using gradlew. Apk compiles successfully, but when I run it, I get a NoClassDefFoundError.
I/Test﹕ Done A!
E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: ru.pvolan.library_b.ClassB
at ru.pvolan.somelibrary.ClassA.doSomething(ClassA.java:12)
...
transitive = true .gradle, , , , , , , ClassB MainActivity - ClassA.
?