简体   繁体   English

一个APK,多个应用模块

[英]One APK, multiple application modules

I have a project setup with 4 modules that flows like this Module1 -> Module2 -> Module3 Module4我有一个包含 4 个模块的项目设置,这些模块的流程类似于 Module1 -> Module2 -> Module3 Module4

Module1 and Module4 are both entry points in to the app and need to have their own launch icons Module1 和 Module4 都是应用程序的入口点,需要有自己的启动图标

Before I split the app in to modules this worked fine but when I split this into modules Modules 1 and 4 are are treated independent and I can either launch one or the other.在我将应用程序拆分为模块之前,这工作正常,但是当我将其拆分为模块时,模块 1 和模块 4 被视为独立的,我可以启动一个或另一个。

This is fine while developing the app but what I want at the end is to generate one APK that contains all modules and create 2 launcher icons when installed, but this isn't happening because it seems to generate 2 APKs这在开发应用程序时很好,但我最终想要的是生成一个包含所有模块的 APK 并在安装时创建 2 个启动器图标,但这并没有发生,因为它似乎生成了 2 个 APK

How do I need to organise this to generate one APK?我需要如何组织它以生成一个 APK?

I figured it out.我想到了。

It needs a bit more than just setting the intent filter so I thought I would explain it here in case anyone else is trying this.它需要的不仅仅是设置意图过滤器,所以我想我会在这里解释一下,以防其他人尝试这样做。

Module1 is the application module, Module4 needs to be a library with just the bare definition for an activity. Module1 是应用程序模块,Module4 需要是一个仅包含活动定义的库。

Then in Module1 manifest you need to create an activity alias to Module4然后在 Module1 清单中,您需要为 Module4 创建一个活动别名

The process is decribed well here..这个过程在这里描述得很好..

http://blog.danlew.net/2014/01/16/preserve-your-launchers-use-activity-alias/ http://blog.danlew.net/2014/01/16/preserve-your-launchers-use-activity-alias/

Also because of this Module1 now has a dependency on Module4 too也因为这个 Module1 现在也依赖于 Module4

In your Manifest file write this code at both entry point .在您的清单文件中,在两个入口点 . it will generate two instance .它将生成两个实例。 for ex like this像这样的前任

 <activity
        android:name=".Activity.Your_module1_entry_activity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

and for your second module和你的第二个模块

 <activity
        android:name=".Activity.your_module2_entry_activity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM