Android開發之~java.lang.ClassNotFoundException: Didn't find class "android.view.x" on path: ...
阿新 • • 發佈:2019-02-14
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————————————–