可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Before, my program run well. But When I just updated my Android studio to the latest version (2.2 built on 15-sept-16), I am having the following error. When I built it, it says: Built sucessfully, but this error appears when I run my program:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.androidtutorial, PID: 28293
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.example.androidtutorial-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.androidtutorial-2/lib/x86,
/system/lib, /vendor/lib]]
at
android.app.ActivityThread.installProvider(ActivityThread.java:5814)
at
android.app.ActivityThread.installContentProviders(ActivityThread.java:5403)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5342)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class
"com.google.firebase.provider.FirebaseInitProvider" on path:
DexPathList[[zip file
"/data/app/com.example.androidtutorial-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.androidtutorial-2/lib/x86,
/system/lib, /vendor/lib]]
at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at
android.app.ActivityThread.installProvider(ActivityThread.java:5799)
at
android.app.ActivityThread.installContentProviders(ActivityThread.java:5403)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5342)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I already looked at other questions but the problem is not the same.
What am I doing wrong? Please help
回答1:
In app module build.gradle
android {
...
defaultConfig {
multiDexEnabled true
...
}
}
dependencies {
// add dependency
compile 'com.android.support:multidex:1.0.1'
}
Change name in AndroidManifest.xml
<application
....
android:name=".MyApplication">
// ...
</application>
Crate a MyApplication.java file
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
For MORE details can see this link.
回答2:
It seems you have a problem with Over 64K Methods and then tried to resolved it with multiDexEnabled true
in build.gradle (app module). But you need to add more than:
add: compile 'com.android.support:multidex:1.0.0'
in dependencies of build.gradle
Extends your Application class to MultiDexApplication. and add MultiDex.install(this);
in onCreated
method of Application class.
your issue should be resolved
refer link: https://developer.android.com/studio/build/multidex.html
回答3:
This works great which you add multidex support in manifest, when ever i encounter problem i got it fixed this way more over 64K.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
回答4:
just remove the google play services dependencies if you are including it. I am able to fix this error everytime using this. If you are using google maps or any other specific google service then include the dependency for that particular service only. Also try to check the version of google play service dependency.
回答5:
app=>build.gradle
android {
.....
defaultConfig {
......
multiDexEnabled true//add this line
}
......
dependencies{
compile 'com.android.support:multidex:1.0.1'//add this line
}
In manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
....
<application
....
android:name="android.support.multidex.MultiDexApplication"
...>
<activity />
...
</application>
</manifest>
回答6:
I got the same error. I resolved it by :
1) Removing unnecessary packages in the build.gralde.
2) Disabling the Firebase plugin
3) Upgrading the build tool to the latest
回答7:
I got the same error and resolved it using:
- Clean/Rebuild your Project.
- Restart Android Studio.
- Update all SDK tools and Android Studio.
- Clear Cache and Clear Data on Device.
回答8:
A simple solution that works for me after trying all of these solution is by deleting outputs folder under project\app\build\ and rebuilding project will let it to running state.
回答9:
Add following line to Manifest.xml
<application
android:name="android.support.multidex.MultiDexApplication"
Add this sn App level build.gradle file
defaultConfig {
multiDexEnabled true
}
......
dependencies {
compile 'com.android.support:multidex:1.0.1'
}