我有一個主要編寫在Kotlin中的項目,但有一些Java類。項目目前進展順利,我想補充的不同環境之間切換,爲此我使用的香料的可能性:帶有產品風味和Kotlin的ClassNotFoundException
productFlavors {
prod {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'true'
applicationId = "com.myapp"
}
beta {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'true'
applicationId = "com.myapp.beta"
}
dev {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'false'
applicationId = "com.myapp.dev"
}
}
然而,當我在一個味道,不生產(不改變的applicationID運行)我得到一個ClassDefNotFoundException Java類:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.beta.ui.view.ScrollBehavior" on path: DexPathList[[zip file "/data/app/com.myapp.beta-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.beta-1/lib/arm64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 33 more
我使用過Android Studio 3.0測試版4科特林插件1.1.3-2版本。
構建文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' // Use experimental kapt implementation
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/ttymsd/maven"
}
maven { url 'https://jitpack.io' }
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
sourceSets {
main.java.srcDirs += 'src/main/java'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "default"
productFlavors {
prod {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'true'
applicationId = "com.myapp"
}
beta {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'true'
applicationId = "com.myapp.beta"
}
dev {
dimension "default"
buildConfigField 'boolean', 'FABRIC', 'false'
applicationId = "com.myapp.dev"
}
}
dataBinding {
enabled = true
}
dependencies {
(...)
}
}
清單:在代碼
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/MyTheme">
<activity
android:name=".ui.dashboard.DashboardListActivity"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
相關部分:
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:theme="@style/MycujooPlayerTheme.AppBarOverlay"
app:layout_behavior=".ui.view.ScrollBehavior">
徹底清潔和重建是否解決了這個問題?是否立即運行修復它? – nhaarman
我從來沒有即時運行(它很爛)。清潔和重建不能修復它 –
請張貼您的清單包 – crgarridos