NoClassDefFoundError on Calligraphy library - android

After adding compile 'com.android.support:support-v13:21.0.+' to build.gradle, I had some conflicts on building my app, so I had to add multiDexEnabled = true to defaultConfig inside build.gradle. Those conflict are gone, but i got another exception (on opening the app) for the missing calligraphy library:
java.lang.NoClassDefFoundError: uk.co.chrisjenx.calligraphy.R$attr
at uk.co.chrisjenx.calligraphy.CalligraphyConfig$Builder.<init>(CalligraphyConfig.java:150)
at com.taxiyaab.android.util.ApplicationClass.onCreate(ApplicationClass.java:120)
at newapp.com.taxiyaab.taxiyaab.PassengerApplication.onCreate(PassengerApplication.java:68)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4462)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at dalvik.system.NativeStart.main(Native Method)
My latest sdk build tools version is 22.0.1. Has anybody faced this issue before?

If you support API levels under 21, your Application class should extend MultiDexApplication from the support library.
class MyApplication extends MultiDexApplication
If you do not have a custom Application class, than you should add the MultiDexApplication class to your manifest directly
<application
android:name="android.support.multidex.MultiDexApplication">
</application>
See https://developer.android.com/tools/building/multidex.html

If your application extends from Application then override attachBaseContext inside Application i.e
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
Also need to add dependency
compile 'com.android.support:multidex:1.0.1'

Goodlife is here again to the rescue .
Add this line to ur java file that extends application.
public void onCreate() {
super.onCreate();
mInstance = this;
//ADD MULTIDEX.INSTALL(THIS) SOLVED MY SIMILAR PROBLEM
MultiDex.install(this);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Roboto-Regular.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
}

Yes,update to multidex 1.0.2
and add Mulitidex.install(this) to the class extending application

MultiDex.install(this);
This can fix the problem.

What i did was too update the compiling library in app level gradle file.
compile 'com.android.support:multidex:1.0.0'
I updated it too
compile 'com.android.support:multidex:1.0.1'
and it worked fine for me.
Maybe this helps someone.

Related

Unable to instantiate appComponentFactory or Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList [duplicate]

I don't know what to do about the following errors, I've searched the web but not found anything:
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.example.padmw-CXElJ_vfrfm3y7py3CPsJw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:338)
at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5388)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1733)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.SystemServer.run(SystemServer.java:454)
at com.android.server.SystemServer.main(SystemServer.java:294)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)
and :
2019-08-29 00:19:24.071 1853-1853/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.example.padmw-CXElJ_vfrfm3y7py3CPsJw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:338)
at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5388)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1733)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at com.android.server.SystemServer.run(SystemServer.java:454)
at com.android.server.SystemServer.main(SystemServer.java:294)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)
my dependencies in gradle app :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
}
apply plugin: 'com.google.gms.google-services'
Adding Java 1.8 compatibility to my module-level build.gradle fixed this for me (non-release build with multidex enabled).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
Unfortunately I'm not sure why :)
This error message is caused on API level 28+ by:AppComponentFactory extends android.app.AppComponentFactory
This means that on API 28+ one can use tools:remove ...
tools:remove="android:appComponentFactory"
tools:targetApi="p"
In my case, the code works on one of my teammates' machine.
These steps made it work for me too:
Close project
Remove the project from the list in the welcome screen
Open the project again
This is a solution to another problem, that I also found here in SO. It's worth a try when Invalidate and Restart doesn't solve it for you.
It may sound totally unrelated, but I have seen this problem also when by mistake I have overridden wrong on Activity#onCreate() method
i.e.
public void onCreate(#Nullable Bundle savedInstanceState,
#Nullable PersistableBundle persistentState)
Instead of
protected void onCreate(#Nullable Bundle savedInstanceState)
So, please check that also.
The second one is the one that you probably need.
Please refer to documentation for the details of these two methods.
Seems to be a bug, check the next link in the issue tracker:
https://issuetracker.google.com/issues/137646829
See java.lang.ClassNotFoundException: Didn't find class "com.my_app_name.androidx".
Remove from AndroidManifest:
<application
...
android:appComponentFactory="androidx"
tools:replace="android:appComponentFactory"
>
These lines appeared a year ago after migrating to AndroidX. I removed them, now it doesn't show the exception.
For Xamarin folks running into this problem: I started to see this problem when upgrading from Xamarin.Forms 4.x to 5.0. With AndroidX changes that I wasn't aware when I've done the upgrade the min SDK version needs to be changed to 29 on the android manifest file, something like:
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="30" />
For anyone facing the same problem in the multi-Module project:->
In my case I had a multi-module project using the Jetpack compose for the presentation layer
Just Clean the project
Rebuild it
Then again run the project
If you are using an emulator, try the wipe data option. This worked for me.
In my case, I was using a library that has an interface that was inheriting a View.OnClickListener interface.
This error can be caused due to using both androidx and legacy android support libraries
Just open project structure and go to Dependencies and select All Modules and check is there any library which contains android.support
Just replace that with androidx version for that library
In the latest versions of android studio, just REMOVE these lines if it is there inside the manifest file
<application
...
tools:replace="android:appComponentFactory" // REMOVE THIS
android:appComponentFactory="androidx" // REMOVE THIS
>
If still there is issue check this
https://stackoverflow.com/a/74523286/6236959
In my case ,that was because of a little mistake in one of my layouts.
I removed one > at the end of a view tag accidentlly.
Check your
xml
files.
After reviewing the Android Issue Tracker bug report mentioned previously, I saw a mention about multidex support. I had no multidex flags specified in my project, so I tried setting the flag to false on all modules in my project, and the exception went away.
This was not a permanent solution; the problem returned a few builds later.
add below code to gradle.properties
android.enableJetifier=true
android.useAndroidX=true
or you can choose migrate to androidX in refactor -> Migrate to androidX.
In my case, add android.enableR8=false in the gradle.properties.
did u create fragments?
ok if you create fragments with classes and after that you have to create a class to call those fragments. and if you use switch this cane be like this
`public Fragment getItem(int i) {
// you have create a switch to get positions using i.
switch (i) {
case 0:
ChatsFragment chatsFragment = new ChatsFragment();
return chatsFragment;
case 1:
GroupsFragment groupsFragment = new GroupsFragment();
return groupsFragment;
case 2:
ContactsFragment contactsFragment = new ContactsFragment();
return contactsFragment;
default:
return null;
}
}
#Override
public int getCount() {
return 3;//error can be happen if u use default 0, use fragment counts in here.
}`
in this case you can see 3 cases in switch
and the public int getCount() the return value should be 3 not default value 0.
See your error must be close to this one. i got same kind of error and i solved it.

android.support.v4.content.FileProvider class not found in android Kitkat

I am using FileProvider in my app. As usual I declared <Provider> tag in AndroidManifest.xml file as below.
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.jk.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
When I run it on android device which has lollipop version it works fine. when I try it on kitkat version it shows following errors:
FATAL EXCEPTION: main
Process: com.jk.android.perfectphotoeditor2018, PID: 24992
java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5071)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5299)
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:932)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.jk.android.perfectphotoeditor2018-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.jk.android.perfectphotoeditor2018-2, /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:5056)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4648) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588) 
at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1290) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5299) 
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:932) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:748) 
at dalvik.system.NativeStart.main(Native Method)
I had tried many solutions like this but it doesn't work for me. so, help me for solve this problem.
build.gradle dependencies:
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
testCompile 'junit:junit:4.12'
/* Add the CSDK framework dependencies (Make sure these version numbers are correct) */
// compile 'com.aviary.android.feather.sdk:aviary-sdk:3.6.3'
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.adobe.creativesdk.foundation:auth:0.9.1251'
compile 'com.adobe.creativesdk:image:4.8.4'
compile 'com.localytics.android:library:4.0.1'
compile 'com.android.support:design:25.4.0'
compile 'com.android.support:multidex:1.0.2'
compile 'com.android.support:support-v4:25.4.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.github.bumptech.glide:glide:4.3.1'
compile 'com.google.android.gms:play-services-ads:9.4.0'
implementation 'com.android.support:support-v4:25.4.0'
}
If you have migrated to AndroidX you have to change the name in AndroidManifest.xml to androidx.core.content.FileProvider
That was the crash in my case.
I have the same question, and this documentation solve my problem.
https://developer.android.com/studio/build/multidexandroid multidex
before android 5.0, you must use follow ways to multidex:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 28
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}
and then modify application, select any one of three ways:
if you not implement application:
<?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>
if you have custom application, you can modify like this:
public class MyApplication extends MultiDexApplication { ... }
if you have replace base application, you can modify like this:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Hope this can solve you problem.
The following code works for me (I've migrated to AndroidX):
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
tools:ignore="WrongManifestParent">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
in my project when set "multiDexEnabled" false, error fixed.
go to manifest and add
android {
defaultConfig {
multiDexEnabled false
}}
hope this is helpful
Just delete the intermediates folder.
After thorough reading of Android Multidex documentation, I found that there is one configuration we generally miss which causes java.lang.NoClassDefFoundError. If you have done regular multidex configuration for 65K reference limit and and still unable to get rid of java.lang.NoClassDefFoundError then you must follow these steps.
Create a file called multidex-config.txt at app level(same directory as the build.gradle file)
Add following line (the absolute class name for which you are getting exception)
android.support.v4.content.FileProvider
Modify your build.gradle as follow
android {
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
...
}
}
}
Note : You can add it for specific build type or both by declaring it in defaultConfig.
What happens when you build a multidex enabled app :
The Android build tools construct a primary DEX file (classes.dex) and supporting DEX files (classes2.dex, classes3.dex, and so on) as needed. The build system then packages all DEX files into your APK.
At runtime, the multidex APIs use a special class loader to search all of the available DEX files for your methods (instead of searching only in the main classes.dex file).
Cause of Exception :
When building each DEX file for a multidex app, the build tools perform complex decision-making to determine which classes are needed in the primary DEX file so that your app can start successfully. If any class that's required during startup is not provided in the primary DEX file, then your app crashes with the error java.lang.NoClassDefFoundError.
This shouldn't happen for code that's accessed directly from your app code because the build tools recognize those code paths, but it can happen when the code paths are less visible such as when a library you use has complex dependencies. For example, if the code uses introspection or invocation of Java methods from native code, then those classes might not be recognized as required in the primary DEX file.
So if you receive java.lang.NoClassDefFoundError, then you must manually specify these additional classes as required in the primary DEX file by declaring them with the multiDexKeepFile (shown above) or the multiDexKeepProguard (refer documentation) property in your build type. If a class is matched in either the multiDexKeepFile or the multiDexKeepProguard file, then that class is added to the primary DEX file.
For complete documentation on multidex refer https://developer.android.com/studio/build/multidex
Click to AndroidManifest.xml look at the bottom of the files page you gonna see "Text" and "Merged Manifes" then click to "Merged Manifest" -> Search for "android.support.v4.content.FileProvider" then change it with "androidx.core.content.FileProvider"
Thats it, exact solution.
change
<provider android:name="android.support.v4.content.FileProvider"
to
<provider android:name="androidx.core.content.FileProvider"
tested and works for me
FileProvider was introduced with Android API Level 22 which is Lollipop, that is why you did not face the ClassNotFoundException when testing on a Lollipop device. Android Kitkat does not have the FileProvider class and hence you are facing the exception. If you are looking to access files this post should help you out

DexOverflowException after adding com.google.firebase:firebase-firestore:11.4.2

I have a problem after adding compile "com.google.firebase:firebase-firestore:11.4.2" to my build.
As soon as I add that, it also adds com.google.common among other things to my dex file, which is around 27k extra references, thus bursting through the 64k dex limit.
Does anyone know why that is or am I doing something wrong?
Try adding these lines to your build.gradle
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
...
}
This will enable multidex mode, which will allow you to exceed the 64k limit. (Read more here)
API below 21
If you're using an API level below 21, then you also need to add the support library
gradle.build:
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
android.manafest
<?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>
If you use a custom Application class, try using one the of the following
Solution 1
simply override the MultiDexApplication class
public class MyApplication extends MultiDexApplication { ... }
Solution 2
override attachBaseContext and install MultiDex using the install(Application) function
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
You're not doing anything wrong: the Android API for Cloud Firestore is just big. We'll be working on reducing SDK size on the road to GA.
Meanwhile, you need to enable multidex to build if your application is nontrivial.
We actually use very little of com.google.common, so you may be able to say under the 64k method limit by proguarding your application too.
Updating to 11.6.0 fixes this issue

NoClassDefFoundError: com.google.firebase.FirebaseOptions

I keep on getting the NoClassDefFoundError on other test device (4.4.2) that I'm using. But works fine on my test device (Android 5.1).
I tried the solutions that I've googled and nothing seems to work.
I'm using Firebase Realtime Database. Can somebody please help?
Here is the error log:
06-03 01:36:29.607 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseOptions', referenced from method com.google.firebase.FirebaseApp.<init> 06-03 01:36:29.617 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zzb', referenced from method com.google.firebase.FirebaseApp.zzaJ 06-03 01:36:29.621 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApiNotAvailableException', referenced from method com.google.firebase.FirebaseApp.getToken 06-03 01:36:29.629 2655-2655/mobapps.mypersonal.biz.grouptracker E/dalvikvm: Could not find class 'com.google.firebase.FirebaseApp$zza', referenced from method com.google.firebase.FirebaseApp.zza 06-03 01:36:29.639 2655-2655/mobapps.mypersonal.biz.grouptracker E/AndroidRuntime: FATAL EXCEPTION: main
Process: mobapps.mypersonal.biz.grouptracker, PID: 2655
java.lang.NoClassDefFoundError: com.google.firebase.FirebaseOptions
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1656)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1627)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5079)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4653)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5363)
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:828)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
at dalvik.system.NativeStart.main(Native Method)
This is what solved the problem for me:
Add compile 'com.android.support:multidex:1.0.2' to
app/build.gradle.
Add android:name="android.support.multidex.MultiDexApplication" to the application tag in AndroidManifest.xml.
If you are using a custom Application class, skip the
AndroidManifest.xml and make your Application class extend MultiDexApplication instead of Application.
This bug is reported with newer versions mostly arround Revision 28,29 and its resolved in newer Play services versions so if you having this issue then make sure you have updated version of Google Play service in your Android studio. as older versions have it. To update Play services version..
Follow these steps:
Go to Android SDK Manager
Go to Extra here you will find as shown in image below, update it to latest version and try to run project.
Then if you are using MultiDex in your Application,then make sure you have correctly done it.
In you App level Build.Gradle file use this code multiDexEnabled true
defaultConfig {
applicationId "com.reversebits.tapanhp.saffer"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
Apply MultiDex dependency in dependencies inside Same file.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:multidex:1.0.1'
}
Then inside your AndroidMenifest.xml file make sure that Application tag have name of MultiDexApplication.
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true">
Note
if you have your own Application class and you are using it in your menifest file then you can initialize multidex in your Application class as follows,
public class AppClass extends Application {
//this will initialize multidex in your own Application class
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Thanks to TapanHP above I got this working quickly for me:
Short Answer:
I had multiDexEnabled= true set in my app/build.gradle file and this ran fine on Android 5.x.x above but any test device with 4.x.x (kit kat) would throw a critical error "Unfortunately, YourAppName has stopped."
Debugger showed:
Could not find class 'com.google.firebase.FirebaseOptions' ....
Note: I also have a custom class that extends Application.
My Solution:
Added the following code to my custom Application class
import android.support.multidex.MultiDex;
public class YourCustomApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
...
}
No more critical crash.
I have the same problem, with this I have solved:
https://stackoverflow.com/a/37364044
You must replace android:name=".app" with android:name="android.support.multidex.MultiDexApplication"

SugarORM + Multidex

I downloaded the SugarORM source to use it as a library module (so I could override the aplication's "attachBaseContext" method.
I have already seen the question SugarORM and multidex, Problem is that I can't figure out how to reference the MultiDex library into my new SugarORM library module.
Can someone help me figuring this out?
Error page screenshot
Create a class java file
public class MultiDex extends SugarApp {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
android.support.multidex.MultiDex.install(this);
}
#Override
public void onCreate() {
super.onCreate();
SugarContext.init(this);
}
#Override
public void onTerminate() {
SugarContext.terminate();
super.onTerminate();
}
}
In Manifest, call the java class file.
<application
.......
android:name=".MultiDex"
......>
Check the version of sugar library
and make sure you complie the latest version of sugar library . Using version like 1.3 will throw some errors with multidex.
add this in your gradle
compile 'com.github.satyan:sugar:1.5'
If possible, extend the MultiDexApplication yourself:
public class MyApplication extends MultiDexApplication
Also, ensure you have followed all steps required to configure MultiDex.
Particularly build.gradle:
android {
defaultConfig {
...
multiDexEnabled = true
}
And AndroidManifest.xml:
<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>

Categories

Resources