我有一个连接到firebase的应用程序。问题是在设备中安装应用程序(在多个设备上工作)。我阅读了很多论坛但没有人工作。我读了here和{{ 3}}等等。谢谢!!
错误就在这里。
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.access$1500(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.access$1500(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)
这是开始类
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();
}
}
}
}
答案 0 :(得分:72)
由于Multidex
的错误,在API 19(&lt; 4.4.2)设备下运行应用程序时,我也遇到了与Firebase相同的问题。然后在解决方案下面为我工作:
在app模块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'
更新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>
包装MyApplication.java文件
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
答案 1 :(得分:23)
在AndroidStudio中尝试这样做:
- Ctrl + Alt + S
- 点击&#34;构建,执行,部署
- 禁用&#34;即时运行&#34;
醇>
这应该有效
答案 2 :(得分:1)
禁用即时运行可以解决我的问题。
Android Studio->首选项->构建,执行,部署->即时运行
-取消选中“启用即时运行...”旁边的框
-单击“确定”
答案 3 :(得分:0)
我遇到了同样的问题,我所做的是从设备/模拟器卸载应用,然后重新安装(从Android Studio,&#39;运行&#39;按钮)。
答案 4 :(得分:0)
如果您最近更改了gradle中的firebase依赖项版本,则可能还需要在Android SDK管理器中更新到最新版本的Google Repository。
如果您当时无法更新Google信息库,请尝试将gradle依赖关系版本更改为更低版本。
答案 5 :(得分:0)
只需在项目AndroidManifest.xml
文件中插入以下行,
如果他们不在应用标记
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />