如何使用 Android Studio 3.3 修复即时应用程序
Posted
技术标签:
【中文标题】如何使用 Android Studio 3.3 修复即时应用程序【英文标题】:How to fix instant app with Android Studio 3.3 【发布时间】:2019-06-28 08:50:33 【问题描述】:我更新到 android Studio 3.3。还有,所有的 SDK。现在我无法运行我的应用程序的即时版本。 我收到以下错误:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':Words:Words:writeAndroidDebugFeatureApplicationId'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.accept(ExecuteActionsTaskExecuter.java:121)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$2.accept(ExecuteActionsTaskExecuter.java:117)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:184)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:110)
at org.gradle.api.internal.tasks.execution.ResolveIncrementalChangesTaskExecuter.execute(ResolveIncrementalChangesTaskExecuter.java:84)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:91)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:74)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:109)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:93)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:45)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:94)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:46)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Expected configuration ':Words:Words:androidDebugFeatureMetadataValues' to contain exactly one file, however, it contains no files.
at org.gradle.api.internal.file.AbstractFileCollection.getSingleFile(AbstractFileCollection.java:61)
at com.android.build.gradle.internal.tasks.ApplicationIdWriterTask.fullTaskAction(ApplicationIdWriterTask.kt:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:48)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:672)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$4.run(ExecuteActionsTaskExecuter.java:338)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:327)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:312)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:158)
at org.gradle.internal.execution.impl.steps.ExecuteStep.execute(ExecuteStep.java:46)
at org.gradle.internal.execution.impl.steps.CancelExecutionStep.execute(CancelExecutionStep.java:34)
at org.gradle.internal.execution.impl.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:69)
at org.gradle.internal.execution.impl.steps.TimeoutStep.execute(TimeoutStep.java:49)
at org.gradle.internal.execution.impl.steps.CatchExceptionStep.execute(CatchExceptionStep.java:34)
at org.gradle.internal.execution.impl.steps.CreateOutputsStep.execute(CreateOutputsStep.java:49)
at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:42)
at org.gradle.internal.execution.impl.steps.SnapshotOutputStep.execute(SnapshotOutputStep.java:28)
at org.gradle.internal.execution.impl.steps.CacheStep.executeWithoutCache(CacheStep.java:133)
at org.gradle.internal.execution.impl.steps.CacheStep.lambda$execute$5(CacheStep.java:83)
at org.gradle.internal.execution.impl.steps.CacheStep$$Lambda$483/988154824.get(Unknown Source)
at java.util.Optional.orElseGet(Optional.java:267)
at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:82)
at org.gradle.internal.execution.impl.steps.CacheStep.execute(CacheStep.java:37)
at org.gradle.internal.execution.impl.steps.PrepareCachingStep.execute(PrepareCachingStep.java:33)
at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:38)
at org.gradle.internal.execution.impl.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:23)
at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:95)
at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:88)
at org.gradle.internal.execution.impl.steps.SkipUpToDateStep$$Lambda$416/111798206.apply(Unknown Source)
at java.util.Optional.map(Optional.java:215)
at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:52)
at org.gradle.internal.execution.impl.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36)
at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:34)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:109)
... 40 more
gradle-wrapper.properties
#Tue Jan 15 12:44:45 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2-all.zip
它适用于旧的 Android Studio Gradle-4.6,但当我尝试回滚时,我收到消息:错误:支持的最低 Gradle 版本为 4.10.1。当前版本是 4.6。
依赖项
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.ads.consent:consent-library:1.0.7'
implementation 'com.google.android.gms:play-services-games:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-ads:17.1.3'
api 'com.android.billingclient:billing:1.1';
// Required by Facebook network
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.facebook.android:audience-network-sdk:5.1.0'
implementation 'com.google.ads.mediation:facebook:5.1.0.0'
implementation "com.google.android.instantapps:instantapps:1.0.0"
settings.gradle
include ':ASCore'
include ":Words:Words"
include ":Words:WordsInstant"
include ':Words:WordsInstall'
*** build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules .
buildscript
ext
/* Build versions */
minSdkVersion = 16
targetSdkVersion = 28
compileSdkVersion = 28
buildToolsVersion = "28.0.3"
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
allprojects
repositories
google()
jcenter()
task clean(type: Delete)
delete rootProject.buildDir
基础模块 build.gradle
apply from: '../../feature.gradle'
apply from: '../version.gradle'
android
defaultConfig
// Feature Version = Instant ap version
versionCode VERSION_CODE
versionName VERSION_NAME
resValue "string", "app_id", "XXXXX"
manifestPlaceholders.appClass = APPLICATION_ID + ".App"
apply plugin: 'com.google.gms.google-services'
即时模块 build.gradle
apply plugin: 'com.android.instantapp'
apply from: '../version.gradle'
android
defaultConfig
applicationId APPLICATION_ID
manifestPlaceholders.appClass = APPLICATION_ID + ".App"
setProperty("archivesBaseName", "$APPLICATION_ID-$VERSION_CODE")
dependencies
implementation project(':Words:Words')
app.gradle
apply plugin: 'com.android.application'
android
buildToolsVersion rootProject.ext.buildToolsVersion
lintOptions
disable 'MissingTranslation'
flavorDimensions "type"
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
//multiDexEnabled true // enable for the MediationTestSuite
resValue "string", "AS_BUILD_TIMESTAMP", "\"" + System.currentTimeMillis() + "\""
signingConfigs
AsgardKey
keyAlias 'XXX'
keyPassword 'XXX'
storeFile file("XXX")
storePassword 'XXX'
v2SigningEnabled true
AsgardKeyDev
keyAlias 'XXX'
keyPassword 'XXX'
storeFile file("XXX")
storePassword 'XXX'
v2SigningEnabled true
buildTypes
debug
resValue "bool", "IS_DEBUG", "true"
signingConfig XXX
release
resValue "bool", "IS_DEBUG", "false"
minifyEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), "$rootProject.projectDir/proguard-rules.pro"
signingConfig XXX
productFlavors
play
dimension 'type'
buildConfigField 'boolean', 'IS_PRO', 'false'
bundle
density.enableSplit = true
abi.enableSplit = true
language
enableSplit = true
applicationVariants.all variant ->
if (variant.buildType.name.equals("release"))
variant.outputs.all output ->
outputFileName = "$applicationId-$versionCode-$variant.flavorName.apk"
if (variant.getBuildType().isMinifyEnabled())
variant.assemble.doLast
copy
from variant.mappingFile
into variant.outputs[0].outputFile.parent
rename String fileName ->
"$applicationId-$versionCode-$variant.flavorName-mapping.txt"
dependencies
implementation project(':ASCore')
apply from: "$rootProject.projectDir/dependencies.gradle"
feature.gradle
apply plugin: 'com.android.feature'
android
buildToolsVersion rootProject.ext.buildToolsVersion
baseFeature true
lintOptions
disable 'MissingTranslation'
flavorDimensions "default"
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "AS_BUILD_TIMESTAMP", "\"" + System.currentTimeMillis() + "\""
signingConfigs
AsgardKey
keyAlias 'XXXX'
keyPassword 'XXXX'
storeFile file("XXXX")
storePassword 'XXXX'
v2SigningEnabled true
AsgardKeyDev
keyAlias 'XXXX'
keyPassword 'XXXX'
storeFile file("XXXX")
storePassword 'XXXX'
v2SigningEnabled true
buildTypes
debug
resValue "bool", "IS_DEBUG", "true"
signingConfig XXXX
release
resValue "bool", "IS_DEBUG", "false"
minifyEnabled false
debuggable false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), "$rootProject.projectDir/proguard-rules.pro"
signingConfig XXXX
productFlavors
android
buildConfigField 'boolean', 'IS_PRO', 'false'
bundle
density.enableSplit = true
abi.enableSplit = true
language
enableSplit = true
dependencies
implementation project(':ASCore')
apply from: "$rootProject.projectDir/dependencies.gradle"
我该如何解决这个问题?
问候 罗纳德
【问题讨论】:
你的gradle插件版本是多少com.android.tools.build:gradle
我使用版本 3.3.0 和 com.google.gms:google-services:4.2.0 来自存储库 google 和 jcenter 并设置以下构建版本 minSdkVersion = 16 targetSdkVersion = 28 compileSdkVersion = 28 buildToolsVersion = “28.0.3”
发布你的项目级别build.gradle
代码
我添加了我的 gradle 文件,ASCore 是我的基础库。
你试过distributionUrl 4.10.1:distributionUrl=http\://services.gradle.org/distributions/gradle-4.10.1-all.zip
in gradle-wrapper.properties
【参考方案1】:
我目前的工作解决方案
从我的基本模块中删除 apply plugin: 'com.google.gms.google-services'
。在旧版本中,这是使 Firebase 分析正常工作所必需的。
现在我使用支持即时应用的 aab 包格式:
https://developer.android.com/topic/google-play-instant/getting-started/instant-enabled-app-bundle
并修改我的 AndroidManifest.xml
<manifest ... xmlns:dist="http://schemas.android.com/apk/distribution">
<dist:module dist:instant="true" />
...
</manifest>
Android Studio 显示警告
选项设置 'android.injected.deploy.instant-app=true' 是 实验性且不受支持。
但它适用于 Google Play 商店、Play 服务和 Firebase :-)
问候 罗纳德
【讨论】:
以上是关于如何使用 Android Studio 3.3 修复即时应用程序的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio 3.3 中缺少 Instant Run
如何在android studio 2.3.3中将html代码显示为文本[重复]
Android Studio 3.3,Advanced Profiling 对所选进程不可用