Didn't find class "com.google.firebase.provider.FirebaseInitProvider"

本文介绍了解决Android应用中出现的ClassNotFoundException和DEX文件方法数超额问题的方法。通过启用MultiDex并调整build.gradle配置,可以有效解决因类数量过多导致的编译错误。

java.lang.ClassNotFoundException: Didn’t find class “com.google.firebase.provider.FirebaseInitProvider” on path: DexPathList[[zip file “/data/app/com.XXX-2.apk”],nativeLibraryDirectories=[/data/app-lib/com.XXX-2, /system/lib]]

使用Multidex解决问题,根据自己的情况使用如下两个方法。

如果您的 minSdkVersion 设置为 21 或更高值,您只需在模块级 build.gradle 文件中将 multiDexEnabled 设置为 true。

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 27
        multiDexEnabled true
    }
    ...
}

如果您的 minSdkVersion 设置为 20 或更低值,则您必须按如下方式使用

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}

接下来就是编辑清单文件,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx">
    <application
        ...
        android:name=".MyApplication">
        ...
    </application>
</manifest>

MyApplication.class

import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

/**
 * @author 小红妹
 * @date 2019/3/5.
 * @describe 注意:MyApplication继承于MultiDexApplication
 * @copyright 
 */
public class MyApplication extends MultiDexApplication {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

这个方法同样也能解决如下DEX文件中容纳请求类方法超额的错误。

Error: Cannot fit requested classes in a single dex file (# methods: 85583 > 65536) 。
----------- * What went wrong: Execution failed for task ':unityLibrary:generateReleaseRFile'. > Could not resolve all files for configuration ':unityLibrary:releaseCompileClasspath'. > Failed to transform firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1) to match attributes {artifactType=android-symbol-with-package-name, org.gradle.status=release}. > Could not find firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1). Searched in the following locations: https://maven.aliyun.com/repository/google/com/google/firebase/firebase-encoders-json/18.0.1/firebase-encoders-json-18.0.1.aar > Failed to transform firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1) to match attributes {artifactType=android-symbol-with-package-name, org.gradle.status=release}. > Could not find firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1). Searched in the following locations: https://maven.aliyun.com/repository/google/com/google/firebase/firebase-encoders-json/18.0.1/firebase-encoders-json-18.0.1.aar > Failed to transform firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1) to match attributes {artifactType=android-symbol-with-package-name, org.gradle.status=release}. > Could not find firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1). Searched in the following locations: https://maven.aliyun.com/repository/google/com/google/firebase/firebase-encoders-json/18.0.1/firebase-encoders-json-18.0.1.aar > Failed to transform firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.1) to match attributes {artifactType=android-symbol-with-package-name, org.gradle.status=release}. > Could not find firebase-encoders-json-18.0.1.aar (com.google.firebase:firebase-encoders-json:18.0.
08-13
当遇到 “Could not find com.google.firebase:firebase-app-unity:13.4.0” 问题时,可尝试以下解决方案: ### 检查仓库配置 确保项目的 `build.gradle` 文件中正确配置了 Google Maven 仓库。在项目根目录的 `build.gradle` 中添加或确认以下内容: ```groovy allprojects { repositories { google() jcenter() // 如果使用 } } ``` ### 检查版本号 确认 `13.4.0` 版本是否存在。可前往 [Maven Central](https://search.maven.org/) 或 [Google Maven Repository](https://maven.google.com/) 搜索该版本。若不存在,可尝试使用其他可用版本。例如,在 `build.gradle` 中更新依赖版本: ```groovy dependencies { implementation 'com.google.firebase:firebase-app-unity:合适的版本号' } ``` ### 同步 Gradle 项目 在 Android Studio 中,点击 “File” -> “Sync Project with Gradle Files” 强制同步项目,确保 Gradle 重新下载依赖。 ### 清理和重建项目 在 Android Studio 中,选择 “Build” -> “Clean Project”,然后选择 “Build” -> “Rebuild Project”,清除旧的构建文件并重新构建项目。 ### 检查网络连接 确保网络连接正常,因为 Gradle 需要从远程仓库下载依赖。若使用了代理,需确保代理配置正确。 ### 检查本地缓存 有时本地 Gradle 缓存可能损坏。可删除 `~/.gradle/caches` 目录下的内容,然后重新同步项目。 ```bash rm -rf ~/.gradle/caches ``` ### 检查 Unity 包管理器 若在 Unity 项目中使用该依赖,可通过 Unity 的包管理器检查和更新 Firebase 相关包。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值