未在路径上找到 class "com.jambod.user.model.ProcessModel":发布 apk 时出现 DexPathList 错误
Didn't find class "com.jambod.user.model.ProcessModel" on path: DexPathList error just in release apk
我编写了一个应用程序,并在 it.For 上使用了 dagger-android
和导航组件,减少了 apk
的大小 我启用了 minifyEnabled
和 shrinkResources
。但是当我生成 apk 并打开应用程序时,应用程序是 crashed.I 跟踪 logcat 并且错误是 Caused by java.lang.ClassNotFoundException
Didn't find class "com.jambod.user.model.ProcessModel" on path: DexPathList
。这是 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 {
}
这是我的申请 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)
}
}
而logcat中的这部分代码移动导航文件有错误:
<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>
根据document我创建了一个multidex-config.txt
文件并添加到build.gradle
但是没有问题solve.This是build.gradle
文件:
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'
}
}
因为您正在使用 "minifyEnabled true"
和混淆器。 "minifyEnabled true" 有时会删除您在应用中使用的模型 classes。在 Gradle 脚本 -> proguard-rules.pro 文件中添加以下行。下面一行会将 class 及其成员保留到您的最终 APK 中。
-keepclasseswithmembernames class com.jambod.user.model.ProcessModel.** { *; }
我编写了一个应用程序,并在 it.For 上使用了 dagger-android
和导航组件,减少了 apk
的大小 我启用了 minifyEnabled
和 shrinkResources
。但是当我生成 apk 并打开应用程序时,应用程序是 crashed.I 跟踪 logcat 并且错误是 Caused by java.lang.ClassNotFoundException
Didn't find class "com.jambod.user.model.ProcessModel" on path: DexPathList
。这是 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 {
}
这是我的申请 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)
}
}
而logcat中的这部分代码移动导航文件有错误:
<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>
根据document我创建了一个multidex-config.txt
文件并添加到build.gradle
但是没有问题solve.This是build.gradle
文件:
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'
}
}
因为您正在使用 "minifyEnabled true"
和混淆器。 "minifyEnabled true" 有时会删除您在应用中使用的模型 classes。在 Gradle 脚本 -> proguard-rules.pro 文件中添加以下行。下面一行会将 class 及其成员保留到您的最终 APK 中。
-keepclasseswithmembernames class com.jambod.user.model.ProcessModel.** { *; }