android - 如何在口味之间使用不同的包名?

标签 android merge manifest android-flavors

我正在尝试创建一个具有 2 种风格的项目:免费版和专业版(版本)。

我的应用程序已经在 PlayStore 中以不同的包(例如:com.example.appfree 和 com.example.app)

这是我的build.gradle:

defaultConfig {
   applicationId "com.example.appfree"
}
productFlavors{
   lite {
       applicationIdSuffix 'lite'
   }

   pro {

   }
}

这是我的 list 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.app">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

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

        <activity android:name=".MainActivity"/>

    </application>

</manifest>

我尝试上传一个免费和专业版本的构建 apk。 Pro flavor还可以,但是free flavor不被谷歌接受,因为包不对。我该如何解决这个问题?

====== 已解决:====== applicationIdSuffix 仅适用于 buildTypes。

最佳答案

借助新的 Android Gradle 构建系统,您可以轻松构建应用的多个不同版本;例如,您可以构建“免费”版本和“专业”版本的应用程序(使用 flavors),并且这些版本在 Google Play 商店中应该有不同的包,这样它们就可以单独安装和购买,都安装在同时,依此类推。同样,您也可以构建应用的“调试”和“alpha”和“beta”版本(使用构建类型),这些也可以类似地有助于独特的包名称。

应用程序/build.gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 19
    buildToolsVersion "19.1"
    defaultConfig {
        applicationId "com.example.my.app"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
...

应用程序/build.gradle:

productFlavors {
    pro {
        applicationId = "com.example.my.pkg.pro"
    }
    free {
        applicationId = "com.example.my.pkg.free"
    }
}

buildTypes {
    debug {
        applicationIdSuffix ".debug"
    }
}
....

来自 Android Studio Project Site - ApplicationId versus PackageName

关于android - 如何在口味之间使用不同的包名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39552590/

相关文章:

android - 如何让我的 android 模拟器更快?

javascript - 按值合并数组中的对象并获取每个对象的计数

Android 资源 $NotFoundException 计算表达式时 - Kotlin

android - 如何在微调器中设置带有图像下划线的下拉箭头

Android,没有模拟器的基本代码测试

java - android "use $ instead of ."生成无法解析符号

class - Puppet: "Could not find class"在 list /模块更改后*经常*出现一次打嗝

sql-server - Sqoop & Hadoop - 如何在 lastmodified 模式下加入/合并 Sqoop 导入的旧数据和新数据?

r - 根据公共(public)值合并同一数据框中的行

Java:找不到主类。程序将会退出