Android: Can you add activities to the Instant App module?

走远了吗. 提交于 2019-12-18 09:44:31

问题


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

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.

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.

EDIT: 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.

回答1:


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

From the documentation:

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.

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

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')
}

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

These will be compiled like this:

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


来源:https://stackoverflow.com/questions/47425735/android-can-you-add-activities-to-the-instant-app-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!