Android开发之~java.lang.ClassNotFoundException: Didn't find class "android.view.x" on path: ...

Process: com.vincent.example, PID: 10424
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vincent.example/com.vincent.example.ui.activity.MainActivity}: android.view.InflateException: Binary XML file line #32: Binary XML file line #1: Error inflating class x
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                       at android.os.Looper.loop(Looper.java:156)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6523)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)
                                                    Caused by: android.view.InflateException: Binary XML file line #32: 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 "/data/app/com.vincent.example-2/base.apk"],nativeLibraryDirectories=[/data/app/com.vincent.example-2/lib/arm64, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/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.view.LayoutInflater.createView(LayoutInflater.java:616)
                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:711)
                                                       at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:74)
                                                       at com.android.internal.policy.HwPhoneLayoutInflater.onCreateView(HwPhoneLayoutInflater.java:107)
                                                       at android.view.LayoutInflater.onCreateView(LayoutInflater.java:728)
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:796)
                                                       at android.view.LayoutInflater.parseInclude(LayoutInflater.java:975)
                                                       at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
                                                       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:832)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:432)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                       at com.vincent.example.base.BaseActivity.setContentView(BaseActivity.java:114)
                                                       at com.vincent.example.ui.activity.MainActivity.onCreate(MainActivity.java:34)
                                                       at android.app.Activity.performCreate(Activity.java:6910)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
                                                       at android.os.Handler.dispatchMessage(Handler.java:105)
                                                       at android.os.Looper.loop(Looper.java:156)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6523)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

报错如上,debug版本正常,正式版打包错误..后来比对配置发现正式版使用了资源压缩,可能是资源压缩导致出现的闪退..

解决:
在打包配置中设置shrinkResources为false

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.vincent.example"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            storeFile file("../key/MyUtils.jks")
            storePassword '...'
            keyAlias '...'
            keyPassword '....'
        }
    }

    buildTypes {

        debug {
            ...
            //移除无用的resource文件 设置为true可能为导致闪退
            shrinkResources false
            ...
        }

        release {
            ...
            //移除无用的resource文件 设置为true可能为导致闪退
            shrinkResources false
            ...
        }
    }




    lintOptions{
        checkReleaseBuilds false
        abortOnError false
    }

}

dependencies {
   ...
       ...
           ...
}

———————————–2017年9月4日18:02:52————————————–

猜你喜欢

转载自blog.csdn.net/pkandroid/article/details/77840187