0

yesteday I update Android Studio to the new 3.5 version. After restarting my PC, Android Studio wasn't able to compile my app any more. I have 3 errors like this:

App.java:29: Error: This method contains native references and will be minified. [KeepMissing]

in two different Java files, where I call some native methods

I know that version 3.5 has R8 as default code obfuscator, so in my build.gradle I commented useProguard false/true from my debug/release build type. It looks like this now:

buildTypes {
    debug {
        debuggable true
        jniDebuggable true
        signingConfig signingConfigs.debug
        minifyEnabled false //shrink
        //useProguard false //obfuscate
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        ndk {
            debuggable = true
        }
    }
    release {
        debuggable false
        jniDebuggable false
        signingConfig signingConfigs.release
        minifyEnabled true //shrink
        //useProguard false //obfuscate
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        ndk {
            debuggable = false
        }
    }
}    

How can I solve this problem?

shizhen
  • 12,251
  • 9
  • 52
  • 88
neo87
  • 51
  • 2
  • 6
  • Update your proguard-rules.pro to disable obfuscation either completely or for specific classes/methods. See e.g. https://stackoverflow.com/questions/51860843/how-to-turn-off-only-the-obfuscation-in-android-r8 – Michael Aug 28 '19 at 14:37
  • Thank you for your reply! I tried adding -dontobfuscate as the first code line in my proguard-rules.pro file, but I keep continue getting the mensioned error. Here is the complete log of the error: FAILURE: Build failed with an exception. C:\[packagename]\App.java:29: Error: This method contains native references and will be minified. [KeepMissing] public native String stringFromJNI(); ~~~~~~~~~~ * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. – neo87 Aug 28 '19 at 15:46
  • Mmm something strange, i commented all references to any native C code, and now I get other errors, like: LoginViewModel.java:158: Error: Missing permissions required by TelephonyManager.getDeviceId: android.permission.READ_PRIVILEGED_PHONE_STATE [MissingPermission] return ((TelephonyManager)getApplication().getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); whitch I requested my fragment. And StartupActivity.java:91: Error: Overriding method should call super.onSaveInstanceState [MissingSuperCall] Previously they where only warnings, now fatal errors? – neo87 Aug 28 '19 at 16:14
  • 1
    I just solved by deleting .gradle, .idea folders and all .iml files in my project! – neo87 Aug 29 '19 at 12:34
  • Check this thread [Android/java: Transition / Migration from ProGuard to R8?](https://stackoverflow.com/a/52921486/8034839) to see if it helps. – shizhen Aug 30 '19 at 01:47

1 Answers1

0

Proguard rules are changed for a lot of libraries since R8 is added. For example, Moshi has updated rules: https://github.com/square/moshi/blob/master/moshi/src/main/resources/META-INF/proguard/moshi.pro so it can work with R8. Please check other libraries and add new rules

Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55