Android 多应用:如何在一个项目中创建两个应用?
Android multi app: how to create two apps within one project?
我有一个即将完成的 Java 应用程序带有身份验证,需要向该项目添加另一个应用程序以重用授权代码,例如。
据我所知,可能会有某种带有不同图标的两个“主要活动”来分别启动它们。我也无法检查此信息,因为不知道这个命名方式和之前的任何尝试以其他方式引导我。
所以问题是如何在 Manifest
中注册这些活动以及如何配置 run
菜单?
或者,如果我错了 - 还有哪些方法可以满足我的要求?
谢谢。
您应该考虑为您的应用使用风格。这允许您为每种口味设置不同的应用程序名称、图标和代码。
这是在主模块的 build.gradle:
中定义两种风格的示例
buildTypes {
debug{...}
release{...}
}
// Specifies one flavor dimension.
flavorDimensions "main"
productFlavors {
demo {
// Assigns this product flavor to the "main" flavor dimension.
// If you are using only one dimension, this property is optional,
// and the plugin automatically assigns all the module's flavors to
// that dimension.
dimension "main"
applicationId "com.appdemo"
versionNameSuffix "-demo"
}
full {
dimension "main"
applicationId "com.appfull"
versionNameSuffix "-full"
}
}
然后您可以通过覆盖每个风格的子目录中的默认文件来设置每个应用程序的资源(图像、代码、字符串...),即 yourmodule/demo/ 和 yourmodule/full/
基本上需要使用活动创建两个入口点并在其中添加图标。
为了以防万一,所以把它留在这里。
<activity android:name=".MainActivity_1"
android:icon="@mipmap/icon_1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity_2"
android:icon="@mipmap/icon_2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
我有一个即将完成的 Java 应用程序带有身份验证,需要向该项目添加另一个应用程序以重用授权代码,例如。
据我所知,可能会有某种带有不同图标的两个“主要活动”来分别启动它们。我也无法检查此信息,因为不知道这个命名方式和之前的任何尝试以其他方式引导我。
所以问题是如何在 Manifest
中注册这些活动以及如何配置 run
菜单?
或者,如果我错了 - 还有哪些方法可以满足我的要求?
谢谢。
您应该考虑为您的应用使用风格。这允许您为每种口味设置不同的应用程序名称、图标和代码。
这是在主模块的 build.gradle:
中定义两种风格的示例buildTypes {
debug{...}
release{...}
}
// Specifies one flavor dimension.
flavorDimensions "main"
productFlavors {
demo {
// Assigns this product flavor to the "main" flavor dimension.
// If you are using only one dimension, this property is optional,
// and the plugin automatically assigns all the module's flavors to
// that dimension.
dimension "main"
applicationId "com.appdemo"
versionNameSuffix "-demo"
}
full {
dimension "main"
applicationId "com.appfull"
versionNameSuffix "-full"
}
}
然后您可以通过覆盖每个风格的子目录中的默认文件来设置每个应用程序的资源(图像、代码、字符串...),即 yourmodule/demo/ 和 yourmodule/full/
基本上需要使用活动创建两个入口点并在其中添加图标。
为了以防万一,所以把它留在这里。
<activity android:name=".MainActivity_1"
android:icon="@mipmap/icon_1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity_2"
android:icon="@mipmap/icon_2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>