0

I am creating an app with schematic library generating SQL database and content provider for me. I am also using a bunch of other libraries, I will include my gradle file in the bottom.

When I deploy my app first, it runs correctly, but if I change something in the code (even if I just insert a log) and redeploy the app it crashes on startup with the following exception:

02-08 20:53:40.279 29400-29400/hu.bendaf.udacity.popularmovies.popularmoviesapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: hu.bendaf.udacity.popularmovies.popularmoviesapp, PID: 29400
    java.lang.RuntimeException: Unable to get provider hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider: java.lang.ClassNotFoundException: Didn't find class "hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider" on path: DexPathList[[zip file "/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/base.apk"],nativeLibraryDirectories=[/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
    at android.app.ActivityThread.installProvider(ActivityThread.java:5856)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
    at android.app.ActivityThread.-wrap2(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: Didn't find class "hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.MovieProvider" on path: DexPathList[[zip file "/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/base.apk"],nativeLibraryDirectories=[/data/app/hu.bendaf.udacity.popularmovies.popularmoviesapp-1/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.ActivityThread.installProvider(ActivityThread.java:5841)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445) 
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384) 
    at android.app.ActivityThread.-wrap2(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

The MovieProvider class should be generated with the schematic library (which is at the first deploy, but it disappears for some reason after).

If I clean the project I can deploy and run my app again correctly, but it's pretty annoying to clean the project after every modification. :)

Can you help me what could cause the problem?

Here is my build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "hu.bendaf.udacity.popularmovies.popularmoviesapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 2
        versionName "1.1"
        vectorDrawables.useSupportLibrary = true
        jackOptions {
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:design:25.1.1'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.android.support:cardview-v7:25.1.1'
    annotationProcessor 'net.simonvt.schematic:schematic-compiler:0.7.0'
    compile 'net.simonvt.schematic:schematic:0.7.0'
}

You can find my whole project on github

bendaf
  • 2,981
  • 5
  • 27
  • 62
  • Hi, I did the (almost) same application on udacity. I used schematic and it works well. Why are you using "annotationProcessor" instead of "compile" in gradle file for the schematic-compiler library? (I used "compile"). Did you try to change it? – Valentino Feb 08 '17 at 20:32
  • well, I just copied the two lines from the schematic library's readme file. I just tried it with compile also, but it doesn't solve the problem :( – bendaf Feb 09 '17 at 10:20

2 Answers2

1

I have solved the problem, it was because I used jack and java 1.8. After I removed these lines from my gradle (and the lambda functions from my app) the crash disappeared:

jackOptions {
    enabled true
}
...
compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
}

Thanks for the help!

bendaf
  • 2,981
  • 5
  • 27
  • 62
0

This could be because of minification, done by ProGuard. You have to specify manually to ignore your external libraries from getting minified.

You can specify it in your proguard-rules.pro file like this..

-keep class com.package.** { *; }

Read more here..

Msp
  • 2,493
  • 2
  • 20
  • 34
  • I've placed this to my proguard-rules.pro file, but it didn't solve the problem :( `-keep class hu.bendaf.udacity.popularmovies.popularmoviesapp.data.generated.** { *; }` – bendaf Feb 09 '17 at 10:13
  • Add this `-keep class hu.bendaf.udacity.** { *; }` – Msp Feb 09 '17 at 10:17
  • Try it for other external libraries too. Also, you should keep classes from `com.android`. – Msp Feb 09 '17 at 10:20
  • still the same crash, I'm sorry :'( – bendaf Feb 09 '17 at 10:27