google.android.gms:play-services-oss-licenses not working after obfuscation

∥☆過路亽.° 提交于 2020-01-15 09:57:08

问题


I'm working on a personal android application. I can't start OssLicensesMenuActivity after obfuscating. Application crashes. It works fine without obfuscation.

startActivity(new Intent(getContext(), com.google.android.gms.oss.licenses.OssLicensesMenuActivity.class));

Here is my release configuration:

release {
            minifyEnabled true
            debuggable true
            shrinkResources true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

I added this line to proguard-rules.pro:

-keep class com.google.android.gms.oss.licenses.** { *; }

Also, I couldn't see a proguard documentation in the official guide: https://developers.google.com/android/guides/opensource

Only release version of my app crashes. The error below is from Logcat.

Can you help me why this error occurs, and what is the solution?

2019-04-21 13:03:01.051 com.myapp.myapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.myapp.myapp, PID: 10763
    android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class x
    Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class x
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.x" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.myapp.myapp-pBk73fi1FLACrYcen4kXlg==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.myapp-pBk73fi1FLACrYcen4kXlg==/lib/arm64, /data/app/com.myapp.myapp-pBk73fi1FLACrYcen4kXlg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.view.LayoutInflater.createView(LayoutInflater.java:606)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
        at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at com.google.android.gms.oss.licenses.zzp.onComplete(:18)
        at com.google.android.gms.tasks.zzj.run(:4)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7045)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)

回答1:


OK i found the problem. I keep drawable resources in res/raw/keep.xml.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:shrinkMode="strict" 
    tools:keep="@drawable/*"/>

I removed the tools:shrinkMode="strict" and problem solved. Everything works fine.



来源:https://stackoverflow.com/questions/55781872/google-android-gmsplay-services-oss-licenses-not-working-after-obfuscation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!