AppCompatDelegate无法实例化自定义视图inflater android.support.v7.app.AppCompatViewInflater

时间:2018-04-03 12:02:49

标签: android gradle android-gradle build.gradle

当获取发布时,我会在应用的所有活动中收到此错误日志

04-03 17:10:54.105 26527-26527/? I/AppCompatDelegate: Failed to instantiate custom view inflater android.support.v7.app.AppCompatViewInflater. Falling back to default.
            java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater
              at java.lang.Class.classForName(Native Method)
              at java.lang.Class.forName(Class.java:309)
              at java.lang.Class.forName(Class.java:273)
              at android.support.v7.app.j.b(AppCompatDelegateImplV9.java:1014)
              at android.support.v7.app.j.onCreateView(AppCompatDelegateImplV9.java:1092)
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
              at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3605)
              at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3677)
              at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1943)
              at android.support.v7.app.j.x(AppCompatDelegateImplV9.java:374)
              at android.support.v7.app.j.w(AppCompatDelegateImplV9.java:323)
              at android.support.v7.app.j.b(AppCompatDelegateImplV9.java:284)
              at android.support.v7.app.c.setContentView(AppCompatActivity.java:139)
              at com.myapp.example.MainActivity.I(MainActivity.java:1523)
              at com.myapp.example.MainActivity.onCreate(MainActivity.java:358)
              at android.app.Activity.performCreate(Activity.java:6010)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
              at android.app.ActivityThread.access$800(ActivityThread.java:155)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5343)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
            Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatViewInflater" on path: DexPathList[[zip file "/data/app/com.myapp.example-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
              at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
              at java.lang.Class.classForName(Native Method) 
              at java.lang.Class.forName(Class.java:309) 
              at java.lang.Class.forName(Class.java:273) 
              at android.support.v7.app.j.b(AppCompatDelegateImplV9.java:1014) 
              at android.support.v7.app.j.onCreateView(AppCompatDelegateImplV9.java:1092) 
              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:482) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:414) 
              at android.view.LayoutInflater.inflate(LayoutInflater.java:365) 
              at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3605) 
              at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3677) 
              at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1943) 
              at android.support.v7.app.j.x(AppCompatDelegateImplV9.java:374) 
              at android.support.v7.app.j.w(AppCompatDelegateImplV9.java:323) 
              at android.support.v7.app.j.b(AppCompatDelegateImplV9.java:284) 
              at android.support.v7.app.c.setContentView(AppCompatActivity.java:139) 
              at com.myapp.example.MainActivity.I(MainActivity.java:1523) 
              at com.myapp.example.MainActivity.onCreate(MainActivity.java:358) 
              at android.app.Activity.performCreate(Activity.java:6010) 
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129) 
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292) 
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413) 
              at android.app.ActivityThread.access$800(ActivityThread.java:155) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317) 
              at android.os.Handler.dispatchMessage(Handler.java:102) 
              at android.os.Looper.loop(Looper.java:135) 
              at android.app.ActivityThread.main(ActivityThread.java:5343) 
              at java.lang.reflect.Method.invoke(Native Method) 
              at java.lang.reflect.Method.invoke(Method.java:372) 
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905) 
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700) 
            Suppressed: java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater
              at java.lang.Class.classForName(Native Method)
              at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
              at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                  ... 32 more
            Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

App Gradle配置如下:

  • compileSdkVersion 27,
  • buildToolsVersion" 25.0.3"
  • minSdkVersion 16,
  • targetSdkVersion 24
  • support_library_version =' 27.1.0',
  • google_play_services_version =' 12.0.1' **

注意:我只在发布版本和版本中收到此错误不在调试版本中。

谢谢。

4 个答案:

答案 0 :(得分:4)

编写Pro Guard规则:

-dontwarn android.support.v7.** -keep class android.support.v7.** { *; } -keep interface android.support.v7.** { *; }

答案 1 :(得分:4)

这似乎是appcompat-v7 27.1.0的错误:https://issuetracker.google.com/issues/74289571

  

2018年3月27日上午07:49

     

开发团队已修复您已报告的问题,并将在未来版本中提供。

您可以更新到较新版本的支持库(如果此修补程序已经发布),或者降级到不存在此错误的先前版本:27.0.2

答案 2 :(得分:0)

您需要为compileSdkVersionbuildToolsVersiontargetSdkVersionsupport library使用相同的版本。因此,您需要使用版本 27

  • compileSdkVersion 27

  • buildToolsVersion "27.0.3"

  • targetSdkVersion 27

  • support_library_version = '27 .1.0'

答案 3 :(得分:0)

我认为他们在27.1.1修正了这个问题。

compileSdkVersion 27
buildToolsVersion '27.0.3'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:cardview-v7:27.1.1'