Android打包gradle 同时安装不同logo不同名称的apk

一、不同包名(可同时安装两个apk)

app的build.gradle:

android {
 
    buildTypes {
        release {
        			//正式包
                    //applicationIdSuffix '.release' //增加包名后缀,可同时安装release和debug
        }
        debug {
                     applicationIdSuffix '.debug' //增加包名后缀,可同时安装release和debug
        }
    }
}

二、不同应用名

app的build.gradle:

android {
 
    buildTypes {
        release {
            //不同app名称
            resValue "string", "app_name", "@string/app_name_release"
        }
        debug {
            //不同app名称
            //type ,name, value
            resValue "string", "app_name", "@string/app_name_debug"
        }
    }
}

strings.xml:

<resources>
    <!--<string name="app_name">MyGradle</string>-->
    <string name="app_name_release">MyGradleRelease</string>
    <string name="app_name_debug">MyGradleDebug</string>
</resources>

AndroidManifest.xml:

<application
        android:label="@string/app_name">
</application>

三、不同logo

app的build.gradle:

android {
 
    buildTypes {
        release {
            //不同app图标
            manifestPlaceholders = [app_icon: "@drawable/logo_release"]
        }
        debug {
            //不同app图标
            manifestPlaceholders = [app_icon: "@mipmap/ic_launcher"]
        }
    }
}

AndroidManifest.xml:

<application
        android:icon="${app_icon}"
        android:roundIcon="${app_icon}">
</application>

四、完整示例:

sign.properties:

storePassword=xq123456
keyPassword=xq123456
keyAlias=key0
storeFile=../mygradle.jks

app的build.gradle:

//获取properties
def keystorePropertiesFile = rootProject.file("sign.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
        debug {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    compileSdkVersion 28
    defaultConfig {
        applicationId "com.xq.mygradle"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            //修改
            signingConfig signingConfigs.release
            //不同app名称
//            resValue "string", "app_name", "@string/app_name_release"
            //不同app图标,名称
            manifestPlaceholders = [app_icon: "@drawable/logo_release",
                                    app_name:"@string/app_name_release"]
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            //修改
            signingConfig signingConfigs.debug
            //不同app名称
            //type ,name, value
//            resValue "string", "app_name", "@string/app_name_debug"
            applicationIdSuffix '.debug' //增加包名后缀,可同时安装release和debug
            //不同app图标,名称
            manifestPlaceholders = [app_icon: "@mipmap/ic_launcher",
                                    app_name: "@string/app_name_debug"]
        }
    }
}

AndroidManifest.xml:

    <application
        android:allowBackup="true"
        android:icon="${app_icon}"
        android:label="${app_name}"
        android:roundIcon="${app_icon}"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值