Android:您可以将活动添加到Instant App模块中吗? [英] Android: Can you add activities to the Instant App module?

查看:341
本文介绍了Android:您可以将活动添加到Instant App模块中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Instant App,但想知道是否可以将活动添加到Instant App模块中.

I'm trying to create an Instant App, but wanted to know if I can add an activity to my Instant App module.

在创建Instant App模块时,android studio向导也不给您添加活动的选项,并且想知道它是否应该为空.我尝试过手动添加活动,但是遇到了一些构建问题.

When creating an Instant App module, the android studio wizard doesn't give you the option to add an activity either and was wondering if it is just supposed to be empty. I've tried adding an activity manually, but ran into some build issues.

在我放弃之前,我只想问一个空的Instant App模块是如何设计的,并且仅应将基本功能模块作为依赖项.

Before I give up I just wanted to ask if an empty Instant App module is how it's designed to be and only supposed to rely on the base feature/feature modules as a dependency.

编辑:当我尝试向com.android.instantapp模块添加活动时,它找不到R资源文件.也出现构建错误:

When I try to add an activity to the com.android.instantapp module, it cant find the R resource file. Also getting a build error :

Error:Execution failed for task :my-instantapp:packageDebugInstantAppBundle'. > 
Expected configuration ':my-instantapp:debugCompileClasspath' to contain exactly 
one file, however, it contains no files.

推荐答案

您不能使用com.android.instantapp插件将代码添加到模块中.

You can't add code to a module using the com.android.instantapp plugin.

从文档中:

在构建即时应用程序时,此模块将使用所有功能并创建即时应用程序APK. 它不包含任何代码或资源;它只包含一个build.gradle文件,并已应用com.android.instantapp插件.

When you build your instant app, this module takes all of the features and creates Instant App APKs. It does not hold any code or resources; it contains only a build.gradle file and has the com.android.instantapp plugin applied to it.

鉴于所有代码都可以通过com.android.feature模块共享,而无需在Instantapp模块中包含代码.

Given that all code can be shared through com.android.feature modules with it's not necessary to have code in the instantapp module.

为实现可重用性,建议在应用com.android.application插件的模块中编写很少甚至没有代码,但要向项目添加依赖项,如下所示:

For reusability it is recommended to have little to no code in modules that apply the com.android.application plugin, but to add dependencies to the projects like this:

dependencies {
    implementation project(':features:hello')
    implementation project(':features:bye')
    implementation project(':features:base')
}

以及依赖com.android.feature插件的模块中的宿主代码.

And host code within modules that rely on the com.android.feature plugin.

这些将像这样编译:

|    depending module     |     compiled to     |
|-----------------------------------------------|
| com.android.application | application apk     |
| com.android.instantapp  | apk for each module | <- then packed into a zip file

这篇关于Android:您可以将活动添加到Instant App模块中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆