多功能 Instant App 崩溃问题
Multi-feature Instant App crash issue
我是 android 中的 Instant 应用新手,下面 link 供参考:
https://codelabs.developers.google.com/codelabs/android-instant-apps/#6
具有单一功能的可安装 apk 和免安装应用运行良好。
但是当我尝试 运行 多功能即时应用程序时,它会崩溃(按照上述步骤 - 7 link)。
崩溃报告:
E: FATAL EXCEPTION: main
Process: com.bhaveshdesai.topekaapk, PID: 17609
java.lang.IncompatibleClassChangeError: Structural change of android.support.v4.app.Fragment is hazardous (/data/app/com.bhaveshdesai.topekaapk-PhiyPZ303gxpikP7GugKyA==/oat/x86/split_topekaui.odex at compile time, /data/app/com.bhaveshdesai.topekaapk-PhiyPZ303gxpikP7GugKyA==/oat/x86/base.odex at runtime): Virtual method count off: 111 vs 150
Landroid/support/v4/app/Fragment; (Compile time):
Static fields:
I ACTIVITY_CREATED
I CREATED
I INITIALIZING
I RESUMED
I STARTED
I STOPPED
.....
功能Gradle文件:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
dataBinding {
enabled true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':topeka-base')
}
应用Gradle文件:
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//apply plugin: 'com.android.application'
apply plugin: 'com.android.feature'
android {
baseFeature = true
compileSdkVersion 26
buildToolsVersion "26.0.0"
dataBinding {
enabled = true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
ext {
supportLibVersion = "25.4.0"
espressoVersion = "2.2.2"
androidTestVersion = "0.5"
hamcrestVersion = "1.3"
junitVersion = "4.12"
}
dependencies {
api "com.android.support:appcompat-v7:${supportLibVersion}"
api "com.android.support:cardview-v7:${supportLibVersion}"
api "com.android.support:design:${supportLibVersion}"
api "com.android.support:recyclerview-v7:${supportLibVersion}"
api "com.android.support.test.espresso:espresso-idling-resource:${espressoVersion}"
testApi "junit:junit:${junitVersion}"
androidTestApi("com.android.support.test.espresso:espresso-core:${espressoVersion}") {
exclude module: "espresso-idling-resource"
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test.espresso:espresso-contrib:${espressoVersion}") {
exclude module: "espresso-core"
exclude module: "recyclerview-v7"
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test:rules:${androidTestVersion}") {
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test:runner:${androidTestVersion}") {
exclude group: "com.android.support"
}
androidTestApi "org.hamcrest:hamcrest-core:${hamcrestVersion}"
feature project(":topekaui")
application project(":topekaapk")
}
请帮我解决这个崩溃问题。
IncompatibleClassChangeError
通常发生在您对库进行不兼容的二进制更改并且不重新编译客户端代码时。请参阅 What causes java.lang.IncompatibleClassChangeError?(但这可能不是您问题的真正原因)
您是在哪一步之后遇到崩溃的?
但是,我现在看到的是您的功能 gradle 文件具有以下依赖项 implementation project(':topeka-base')
,而它应该包含 api project(':topeka-base')
。 (假设你的特征 gradle = topeka-ui gradle)
topeka-ui/build.gradle
Replace all pre-generated dependencies with the
following dependency:
dependencies {
api project(':topeka-base')
}
请仔细检查 Codelab 说明,确保您没有遗漏任何步骤。
经过多次尝试,我发现了问题。
问题是由于使用 android.support.v4.app.Fragment
将 android.support.v4.app.Fragment
更改为 android.app.Fragment
后,它的工作。
我是 android 中的 Instant 应用新手,下面 link 供参考: https://codelabs.developers.google.com/codelabs/android-instant-apps/#6
具有单一功能的可安装 apk 和免安装应用运行良好。
但是当我尝试 运行 多功能即时应用程序时,它会崩溃(按照上述步骤 - 7 link)。
崩溃报告:
E: FATAL EXCEPTION: main
Process: com.bhaveshdesai.topekaapk, PID: 17609
java.lang.IncompatibleClassChangeError: Structural change of android.support.v4.app.Fragment is hazardous (/data/app/com.bhaveshdesai.topekaapk-PhiyPZ303gxpikP7GugKyA==/oat/x86/split_topekaui.odex at compile time, /data/app/com.bhaveshdesai.topekaapk-PhiyPZ303gxpikP7GugKyA==/oat/x86/base.odex at runtime): Virtual method count off: 111 vs 150
Landroid/support/v4/app/Fragment; (Compile time):
Static fields:
I ACTIVITY_CREATED
I CREATED
I INITIALIZING
I RESUMED
I STARTED
I STOPPED
.....
功能Gradle文件:
apply plugin: 'com.android.feature'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
dataBinding {
enabled true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':topeka-base')
}
应用Gradle文件:
/*
* Copyright 2015 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//apply plugin: 'com.android.application'
apply plugin: 'com.android.feature'
android {
baseFeature = true
compileSdkVersion 26
buildToolsVersion "26.0.0"
dataBinding {
enabled = true
}
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
ext {
supportLibVersion = "25.4.0"
espressoVersion = "2.2.2"
androidTestVersion = "0.5"
hamcrestVersion = "1.3"
junitVersion = "4.12"
}
dependencies {
api "com.android.support:appcompat-v7:${supportLibVersion}"
api "com.android.support:cardview-v7:${supportLibVersion}"
api "com.android.support:design:${supportLibVersion}"
api "com.android.support:recyclerview-v7:${supportLibVersion}"
api "com.android.support.test.espresso:espresso-idling-resource:${espressoVersion}"
testApi "junit:junit:${junitVersion}"
androidTestApi("com.android.support.test.espresso:espresso-core:${espressoVersion}") {
exclude module: "espresso-idling-resource"
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test.espresso:espresso-contrib:${espressoVersion}") {
exclude module: "espresso-core"
exclude module: "recyclerview-v7"
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test:rules:${androidTestVersion}") {
exclude group: "com.android.support"
}
androidTestApi("com.android.support.test:runner:${androidTestVersion}") {
exclude group: "com.android.support"
}
androidTestApi "org.hamcrest:hamcrest-core:${hamcrestVersion}"
feature project(":topekaui")
application project(":topekaapk")
}
请帮我解决这个崩溃问题。
IncompatibleClassChangeError
通常发生在您对库进行不兼容的二进制更改并且不重新编译客户端代码时。请参阅 What causes java.lang.IncompatibleClassChangeError?(但这可能不是您问题的真正原因)
您是在哪一步之后遇到崩溃的?
但是,我现在看到的是您的功能 gradle 文件具有以下依赖项 implementation project(':topeka-base')
,而它应该包含 api project(':topeka-base')
。 (假设你的特征 gradle = topeka-ui gradle)
topeka-ui/build.gradle
Replace all pre-generated dependencies with the following dependency:
dependencies { api project(':topeka-base') }
请仔细检查 Codelab 说明,确保您没有遗漏任何步骤。
经过多次尝试,我发现了问题。
问题是由于使用 android.support.v4.app.Fragment
将 android.support.v4.app.Fragment
更改为 android.app.Fragment
后,它的工作。