I write an application and I use dagger-android
and navigation component on it.For reduce size of apk
I enable minifyEnabled
and shrinkResources
. But When i generate apk and open app, the app is crashed.I traced the logcat and the error was Caused by java.lang.ClassNotFoundException
Didn't find class "com.jambod.user.model.ProcessModel" on path: DexPathList
. This is code of ProcessModel
:
data class ProcessModel(
var id: String,
var state: String ,
var originLat: Double,
var originLon: Double,
var originAddress: String,
var city: String ,
var client: User ,
var broker: Broker,
var handover: HandOver ,
var startTime: Long ,
var endTime: Long ,
var clientScore: Int,
var role:String,
var isFirstFinishedProcess:Boolean
) : Serializable {
}
And This is my Application class:
class MyApplication : DaggerApplication() {
val TAG="MyApplication"
@Inject
lateinit var mapboxMap: CedarMaps
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
Log.e(TAG,"applicationInjector")
return DaggerAppComponent.builder().application(this).build()
}
override fun onCreate() {
super.onCreate()
Log.e(TAG,"onCreate")
setMapview()
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
Log.e(TAG,"attachBaseContext")
MultiDex.install(this)
}
private fun setMapview() {
mapboxMap.setClientID("jambod-3804728105994932624")
.setClientSecret("b37qDGphbWJvZLqxi8hCuQhrjCXtqKs9V536SyiAAHQP01FzTg3G0iat")
.setContext(this)
}
}
And this part of code mobile-navigation file that in the logcat has error:
<fragment android:id="@+id/detailProcessFragment" android:name="com.jambod.user.ui.DetailProcessFragment"
android:label="fragment_detail_process" tools:layout="@layout/fragment_detail_process">
<argument android:name="KEY_PROCESS"
app:argType="com.jambod.user.model.ProcessModel"
app:nullable="true"
android:defaultValue="@null"/>
</fragment>
According the document I create a multidex-config.txt
file and add it on build.gradle
But the problem did not solve.This is build.gradle
file:
defaultConfig {
applicationId "com.jambod.user"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
multiDexKeepFile file('multidex-config.txt')
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
As you are using "minifyEnabled true"
and proguard. "minifyEnabled true" will some time remove the model classes that you have used in your app. Add below line in Gradle scripts -> proguard-rules.pro file. Below line will keep the class and its members to your final APK.
-keepclasseswithmembernames class com.jambod.user.model.ProcessModel.** { *; }