java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater

Posted

技术标签:

【中文标题】java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater【英文标题】: 【发布时间】:2019-03-10 03:32:26 【问题描述】:

我正在应用程序中使用 Google Pay 实现 Braintree Drop-in UI,我在选择 google pay 时开始出现错误,该对话框显示消息“意外的开发人员错误,请稍后再试”,如下是错误:

Failed to instantiate custom view inflater 

android.support.v7.app.AppCompatViewInflater. Falling back to default.
    
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1)
        at android.support.v7.app.AppCompatDelegateImpl.onCreateView(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:1911)
        at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2579)
        at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2652)
        at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2066)
        at android.support.v7.app.AppCompatDelegateImpl.n(:com.google.android.gms@13280020@13.2.80 (040406-211705629):8)
        at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):48)
        at dip.findViewById(Unknown Source:4)
        at arru.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):5)
        at arrt.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1)
        at com.google.android.gms.wallet.ib.IbChimeraActivity.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):8)
        at com.google.android.chimera.Activity.publicOnCreate(Unknown Source:0)
        at diu.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):6)
        at odi.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):2)
            at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:251)
        at android.app.ActivityThread.main(ActivityThread.java:6572)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)


        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
         Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.app.AppCompatViewInflater" on path: DexPathList[[zip file "/system/framework/com.android.location.provider.jar", zip file "/system/framework/com.android.media.remotedisplay.jar", zip file "/data/app/com.google.android.gms-nZjkHiOnxKIKJV7GOxW-nQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.google.android.gms- 
   nZjkHiOnxKIKJV7GOxW-nQ==/lib/arm64, /data/app/com.google.android.gms-         
   nZjkHiOnxKIKJV7GOxW-nQ==/base.apk!/lib/arm64-v8a, /system/lib64,  
    /vendor/lib64]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                at java.lang.Class.classForName(Native Method) 
                at java.lang.Class.forName(Class.java:453)   
                at java.lang.Class.forName(Class.java:378)     
            at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1) 
            at android.support.v7.app.AppCompatDelegateImpl.onCreateView(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1) 
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772) 
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
            at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
            at com.android.internal.policy.DecorView.onResourcesLoaded(DecorView.java:1911) 
            at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:2579) 
            at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:2652) 
            at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:2066) 
            at android.support.v7.app.AppCompatDelegateImpl.n(:com.google.android.gms@13280020@13.2.80 (040406-211705629):8) 
            at android.support.v7.app.AppCompatDelegateImpl.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):48) 
            at dip.findViewById(Unknown Source:4) 
            at arru.a(:com.google.android.gms@13280020@13.2.80 (040406-211705629):5) 
            at arrt.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):1) 
            at com.google.android.gms.wallet.ib.IbChimeraActivity.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):8) 
            at com.google.android.chimera.Activity.publicOnCreate(Unknown Source:0) 
            at diu.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):6) 
            at odi.onCreate(:com.google.android.gms@13280020@13.2.80 (040406-211705629):2) 
            at android.app.Activity.performCreate(Activity.java:6975) 
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775) 
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) 
            at android.app.ActivityThread.-wrap11(Unknown Source:0) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) 
            at android.os.Handler.dispatchMessage(Handler.java:105) 
            at android.os.Looper.loop(Looper.java:251) 
            at android.app.ActivityThread.main(ActivityThread.java:6572) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

以下是我在gradle中添加的依赖:

 def androidSupportVersion = "27.1.1"  
implementation fileTree(include: ['*.jar'], dir: 'libs')  
implementation "com.android.support:cardview-v7:$androidSupportVersion"   
implementation "com.android.support:recyclerview-v7:$androidSupportVersion"   
implementation "com.android.support:support-v4:$androidSupportVersion"   
implementation "com.android.support:design:$androidSupportVersion"   
implementation "com.android.support:design:$androidSupportVersion"   
implementation "com.google.android.gms:play-services-wallet:16.0.0"   
implementation "com.android.support:customtabs:$androidSupportVersion"   
implementation "com.android.support.constraint:constraint-layout:1.1.3"   
implementation 'com.braintreepayments.api:drop-in:3.+'

Braintree Google Pay 集成代码:

GooglePaymentRequest googlePaymentRequest = new GooglePaymentRequest()
            .transactionInfo(TransactionInfo.newBuilder()
                    .setTotalPrice(priceString)
                    .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
                    .setCurrencyCode("GBP")
                    .build())
            .billingAddressRequired(true)
            .uiRequired(true);

【问题讨论】:

【参考方案1】:

java.lang.ClassNotFoundException: 找不到类 "android.support.v7.app.AppCompatViewInflater"

您的build.gradle 中有两个支持设计依赖项。删除其中一个:

implementation "com.android.support:design:$androidSupportVersion"   
implementation "com.android.support:design:$androidSupportVersion"  // Remove this

更新:看起来像 27.1.1 中的一个错误。尝试更新到28.0.0

def androidSupportVersion = "28.0.0"  

【讨论】:

没看懂,proguard跟这个有什么关系? @Mohsen 是的,第一点是有效的,是我的错误,但仍然给我错误,关于第二点,为什么我需要 proguard? 查看此链接:***.com/questions/49629621/… 这似乎是 27.1.1 中的错误。尝试更新到 28.0.0。【参考方案2】:

确保在 build.gradle 文件中添加 appcompat 支持库作为依赖项。

dependencies 
    implementation 'com.google.android.gms:play-services-wallet:16.0.0'
    implementation 'com.android.support:appcompat-v7:$androidSupportVersion'

【讨论】:

【参考方案3】:

查看the Google Pay troubleshooting guide 可能会有所帮助。

对我来说,ClassNotFoundException 只是一个警告。注意到 Google 在故障排除页面上的建议后,潜在的错误出现在 logcat 中:

Note: The error only becomes visible in logcat after you've pressed OK to close the alert.

点击 OK 后,我收到一条非常具体的错误消息,与我如何组装付款数据 JSON 请求有关。

【讨论】:

以上是关于java.lang.ClassNotFoundException: android.support.v7.app.AppCompatViewInflater的主要内容,如果未能解决你的问题,请参考以下文章