Java “无法获取提供程序 com.google.firebase.provider.FirebaseInitProvider” 错误路径 Android
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39206299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Unable to get provider com.google.firebase.provider.FirebaseInitProvider" Error path Android
提问by azsoftco
I have an Application which is connected to firebase.The problem is when install the app in device(working on several devices).I read a lot of forums and no one works.I read hereand thisand so on.Thanks!!
我有一个连接到 firebase 的应用程序。问题是在设备中安装应用程序时(在多个设备上工作)。我阅读了很多论坛,但没有人工作。我阅读了这里和这个等等。谢谢!
The error is here.
错误就在这里。
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dev.ptruck, PID: 8833
java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.dev.ptruck-17.apk"],nativeLibraryDirectories=[/data/app-lib/com.dev.ptruck-17, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5196)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4788)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728)
at android.app.ActivityThread.access00(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5584)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" on path: DexPathList[[zip file "/data/app/com.dev.ptruck-17.apk"],nativeLibraryDirectories=[/data/app-lib/com.dev.ptruck-17, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.ActivityThread.installProvider(ActivityThread.java:5181)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4788)?
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728)?
at android.app.ActivityThread.access00(ActivityThread.java:166)?
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1343)?
at android.os.Handler.dispatchMessage(Handler.java:102)?
at android.os.Looper.loop(Looper.java:136)?
at android.app.ActivityThread.main(ActivityThread.java:5584)?
at java.lang.reflect.Method.invokeNative(Native Method)?
at java.lang.reflect.Method.invoke(Method.java:515)?
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)?
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)?
at dalvik.system.NativeStart.main(Native Method)?
Here is the start Class
这是开始班
public class StartActivity extends Activity {
private static final String FIREBASE_URL = "https://database.firebaseio.com/";
private Firebase myFirebaseRef = null;
View rootView;
String uid;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Firebase.setAndroidContext(this);
final ProgressBar p = (ProgressBar) findViewById(R.id.start_progress_bar);
}
private void checkUserLogin() {
myFirebaseRef.addAuthStateListener(new Firebase.AuthStateListener() {
@Override
public void onAuthStateChanged(AuthData authData) {
if (authData != null) {
System.out.println(myFirebaseRef.getKey());
Intent toMainActivity = new Intent(getApplicationContext(), MenuActivity.class);
uid = myFirebaseRef.getAuth().getUid();
toMainActivity.putExtra("user_id", uid);
finish();
startActivity(toMainActivity);
} else if (authData == null) {
Intent toMainActivity = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(toMainActivity);
// user is not logged in
}
}
});
}
private Runnable task = new Runnable() {
public void run() {
checkUserLogin();
}
};
@Override
protected void onStart() {
super.onStart();
if(myFirebaseRef == null) {
myFirebaseRef = new Firebase(FIREBASE_URL);
}
Handler handler = new Handler();
handler.postDelayed(task, 3000);
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindDrawables(rootView);
rootView = null;
System.gc();
}
protected void unbindDrawables(View view) {
if (view != null) {
if (view.getBackground() != null) {
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup && !(view instanceof AdapterView)) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
((ViewGroup) view).removeAllViews();
}
}
}
}
}
采纳答案by Garg's
I have also faced same problem with Firebase when run application below API 19(< 4.4.2) devices due to error of Multidex
. Then below solutionwork for me:
由于Multidex
. 然后下面的解决方案对我有用:
In app module build.gradle
在应用模块 build.gradle
android {
...
defaultConfig {
multiDexEnabled true
...
}
}
dependencies {
// add dependency
compile 'com.android.support:multidex:1.0.1'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
update name in AndroidManifest.xml
更新 AndroidManifest.xml 中的名称
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MyApplication"
android:theme="@style/AppTheme">
// ...
</application>
Crate a MyApplication.java file
创建一个 MyApplication.java 文件
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
回答by Lee
I'm having the same issue, what i did is uninstall the app from device/emulator, and then, reinstall it again (from Android Studio, 'run' button).
我遇到了同样的问题,我所做的是从设备/模拟器卸载应用程序,然后再次重新安装(从 Android Studio,“运行”按钮)。
回答by Antonio
In AndroidStudio try to do this:
在 AndroidStudio 中尝试这样做:
- ctrl+alt+s
- Click on "Build, Execution, Deployment
- disable "Instant Run"
- ctrl+alt+s
- 点击“构建、执行、部署
- 禁用“即时运行”
This should work
这应该工作
回答by sats
If you have recently changed the firebase dependency version in your gradle you may need to update to the latest version of Google Repository in the Android SDK manager as well.
如果您最近更改了 gradle 中的 firebase 依赖项版本,您可能还需要在 Android SDK 管理器中更新到最新版本的 Google Repository。
If you cannot update the Google Repository at the time, try changing the gradle dependency version back to lower.
如果您当时无法更新 Google Repository,请尝试将 gradle 依赖项版本改回较低的版本。
回答by Vishalpari Goswami
Just insert below lines in your project AndroidManifest.xml
file,
if they're not in applicationtag
AndroidManifest.xml
如果它们不在应用程序标签中,只需在项目文件中插入以下几行
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
回答by Chris M
Disabling instant run fixed the issue for me.
禁用即时运行为我解决了这个问题。
Android Studio -> Preferences -> Build, Execution, Deployment -> Instant Run
Android Studio -> Preferences -> Build, Execution, Deployment -> Instant Run
-Uncheck the box next to "Enable Instant Run..."
- 取消选中“启用即时运行...”旁边的框
-Click OK
- 单击确定