I use singleton object in my app and provide context to it from Application class.
And i use by lazy {} delegate for set sharedPreferences field. It's working on API 21 and higher, but on API 19 i has a NoClassDefFoundError:
08-04 16:20:24.075 5576-5576/ru.maxim.barybians E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.maxim.barybians, PID: 5576
java.lang.NoClassDefFoundError: ru.maxim.barybians.repository.local.PreferencesManager$sharedPreferences$2
at ru.maxim.barybians.repository.local.PreferencesManager.<clinit>(PreferencesManager.kt:15)
at ru.maxim.barybians.App.onCreate(App.kt:14)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Singleton object
object PreferencesManager {
lateinit var context: Context
private val sharedPreferences: SharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(context) }
App class
class App : Application() {
override fun onCreate() {
super.onCreate()
PreferencesManager.context = applicationContext
}
compileSdkVersion 29
buildToolsVersion "29.0.0"
minSdkVersion 19
targetSdkVersion 29
kotlin_version = '1.3.72'
Gradle Version = 6.1.1
Gradle Plugin Version = 4.0.1
Changing Gradle version or invalidating cache not working for me.
I will be grateful for any help
I finnaly foun the solution. Application crashes because class App inherited from Application. After i change it to MultiDexApplication, application began to work normally.
class App : MultiDexApplication()
Related
I have an application developed with ionic v.1.x and it is integrated with Mobile First 8.
When I install the debug version, it is all OK, but I generated the released version, install it and it crashes.
I have the following error:
Process: {APP_ID}, PID: 20565
java.lang.RuntimeException: Unable to create application com.ibm.MFPApplication: java.lang.IllegalStateException: Unable to extract the trust manager on a.a.f.a#42a0f068, sslSocketFactory is class com.worklight.wlclient.f
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4715)
at android.app.ActivityThread.access$1600(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5579)
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.IllegalStateException: Unable to extract the trust manager on a.a.f.a#42a0f068, sslSocketFactory is class com.worklight.wlclient.f
at a.v$a.a(SourceFile:599)
at com.worklight.wlclient.c.<init>(SourceFile:76)
at com.worklight.wlclient.c.a(SourceFile:246)
at com.worklight.wlclient.a.f.a(SourceFile:181)
at com.worklight.common.a.a(SourceFile:545)
at com.worklight.androidgap.b.a.<init>(SourceFile:54)
at com.worklight.androidgap.b.a.a(SourceFile:85)
at com.ibm.MFPApplication.onCreate(SourceFile:21)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4712)
... 10 more
Force finishing activity {APP_ID}/.MainActivity
I saw that another guy had the same problem, but his solution was install 6.2 Cordova version... I tried that and I get the following error:
Error: cordovaProject.projectConfig.getFileResources is not a function
Add below rules in your proguard-project.txt or proguard-rules.pro file
-keepclassmembers class * implements javax.net.ssl.SSLSocketFactory {
private javax.net.ssl.SSLSocketFactory delegate;
}
For more info :
Obfuscating Android code using Proguard in MobileFirst Foundation 8.0
i'm getting this class not found error on api's below 21 even though google said it supports till api 14
i have tried it on android studio 3.0 beta 6
09-19 17:12:39.273 2794-2794/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxxx, PID: 2794
java.lang.RuntimeException: Unable to get provider android.arch.lifecycle.LifecycleRuntimeTrojanProvider: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.LifecycleRuntimeTrojanProvider" on path: DexPathList[[zip file "/data/app/xxxx-1.apk"],nativeLibraryDirectories=[/data/app-lib/xxxx-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:4793)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4385)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4325)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.LifecycleRuntimeTrojanProvider" on path: DexPathList[[zip file "/data/app/xxxxx-1.apk"],nativeLibraryDirectories=[/data/app-lib/xxxxx-1, /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)
I've been using kotlin for development.
// architecture components
implementation "android.arch.lifecycle:runtime:$arch_version"
implementation "android.arch.lifecycle:extensions:$arch_version"
kapt "android.arch.lifecycle:compiler:$arch_version"
arch version is the latest one ext.arch_version = '1.0.0-alpha9-1'
building tool -> ext.buildToolsVersion = '26.0.1'
i have checked the other solutions says disable minify and proguard i have already tested them
debug {
// applicationIdSuffix '.debug' // Remove to fix Robolectric problem
versionNameSuffix '-DEBUG'
debuggable true
minifyEnabled false
useProguard false
multiDexEnabled true
Disabling Instant Run worked for me. (Settings -> Build, Execution, Deployment -> Instant Run -> uncheck "Enable Instant Run")
I was having the same problem, my app wouldn't run in api 19 devices (4.4) and it was a Dex problem.
I followed google documentation on multidex to solve it
1 - in app gradle, inside defaultConfig enable multidex
defaultConfig{
....
multiDexEnabled true
}
2 - to support multidex in other versions, add this dependency to your app gradle
compile 'com.android.support:multidex:1.0.1'
3 - if you have a class that extends Application, make it extend MultiDexApplication
if you don't, add this to your manifest file inside application tag
android:name="android.support.multidex.MultiDexApplication"
that's it. worked for me
After adding the fabric crashlytics i'm getting error as no class definition found error for MultiPartBuildEntry in android 4.4
java.lang.NoClassDefFoundError: org.apache.http.entity.mime.MultipartEntityBuilder
at clovewearable.commons.social.server.SignUpService.generateMultiPartPayload(SignUpService.java:171)
at clovewearable.commons.social.server.SignUpService.triggerAPICall(SignUpService.java:110)
at clovewearable.commons.social.ui.SignUpFragment.triggerAPICall(SignUpFragment.java:585)
at clovewearable.commons.social.ui.SignUpFragment.validateNormalSignIn(SignUpFragment.java:388)
at clovewearable.commons.social.ui.SignUpFragment.onClick(SignUpFragment.java:427)
at android.view.View.performClick(View.java:4640)
at android.view.View$PerformClick.run(View.java:19421)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
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)
your Application.class should be extended from MultiDexApplication
For that you should add such code in you gradle
android {
defaultConfig {
...
multiDexEnabled true
}
dependencies {
...
compile 'com.android.support:multidex:1.0.2'
}
To initialize the fabric inside a class we have to start the fabric catalyst.
Use the following line inside onCreate to initialize fabric:
Fabric.with(this, new Crashlytics());
I am developing an app using the Google GCM service and it seems to be crashing on all pre-lollipop devices at Launch.. I Have followed google tutorial... and its working on lollipop and marshmallow
here are my project level dependencies
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:1.5.0'
}
I have this in my app level gradle file
compile 'com.google.android.gms:play-services:8.4.0'
and this
apply plugin: 'com.google.gms.google-services'
I have also setup android manifest.. and service classes accordingly and receiving GCM on marshmallow device.
I am having this error.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: itcurves.driver, PID: 12788
java.lang.NoClassDefFoundError: com.google.android.gms.R$string
at com.google.android.gms.measurement.zza.<init>(Unknown Source)
at com.google.android.gms.measurement.zza.zzaR(Unknown Source)
at com.google.android.gms.measurement.internal.zzn.zziJ(Unknown Source)
at com.google.android.gms.measurement.internal.zzz.zza(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.<init>(Unknown Source)
at com.google.android.gms.measurement.internal.zzaa.zzDj(Unknown Source)
at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source)
at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
at android.app.ActivityThread.installProvider(ActivityThread.java:4889)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4476)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4413)
at android.app.ActivityThread.access$1500(ActivityThread.java:142)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5120)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
I had same problem.You are probably facing it on devices prior 5.0 version.The reason why this happen is that version prior to android 5.0 use Dalvik and by default, Dalvik limits apps to a single classes.dex bytecode file per APK.The solution is to use multidex support.
Include in your build.gradle dependencies this:
compile 'com.android.support:multidex:1.0.0'
public class MyApp extends MultiDexApplication {
#Override
public void onCreate() {
super.onCreate();
}
}
than in your Manifest add MultiDexApplication class
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name=".MyApp">
...
</application>
</manifest>
Note: If you already have your application class just extend it with MultiDexApplication class
The the same crash happened after I imported Couchbase Lite Android using either Gradle or jars.
Couldn't really figure out what's going on here as I didn't touch the code and only dropped the jars into the "libs" folder.
// inside Custom Application class
#Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics()); // <===== Crash here!
}
Trace:
07-07 19:37:43.785 15247-15247/? E/AndroidRuntime﹕
FATAL EXCEPTION: main
Process: sg.com.bigspoon.www, PID: 15247
java.lang.NoClassDefFoundError: io.fabric.sdk.android.services.common.ExecutorUtils
at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:202)
at com.crashlytics.android.Crashlytics.<init>(Crashlytics.java:197)
at sg.com.bigspoon.www.data.BigSpoon.onCreate(BigSpoon.java:121)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4541)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
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)
EDIT:
Although this is "fixed". But it is still very bizarre why this is happening. I would enlighten me and I would mark it as correct answer instead.
This is solved by enabling multiDex in build.gradle
android {
defaultConfig {
// Lower than 14 doesn't support multidex
minSdkVersion 14
// Enabling multidex support.
multiDexEnabled true
}
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
SOURCE and more details -->
https://github.com/chrisjenx/Calligraphy/issues/136
https://developer.android.com/tools/building/multidex.html