Update the app name and logo based on the maven android build profile

故事扮演 提交于 2019-12-23 04:15:54

问题


This is my Manifest file

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="20411" android:versionName="2.4.11-SNAPSHOT" package="com.customcompany">

    <uses-percustomssion android:name="android.percustomssion.ACCESS_WIFI_STATE"/>
    <uses-percustomssion android:name="android.percustomssion.CHANGE_WIFI_STATE"/>
    <uses-percustomssion android:name="android.percustomssion.CHANGE_WIFI_MULTICAST_STATE"/>
    <uses-percustomssion android:name="android.percustomssion.ACCESS_NETWORK_STATE"/>
    <uses-percustomssion android:name="android.percustomssion.INTERNET"/>
    <uses-percustomssion android:name="android.percustomssion.READ_LOGS"/>
    <uses-percustomssion android:name="android.percustomssion.WRITE_SETTINGS"/>
    <uses-percustomssion android:name="android.percustomssion.RECORD_AUDIO"/>
    <uses-percustomssion android:name="android.percustomssion.WRITE_EXTERNAL_STORAGE"/>
    <uses-percustomssion android:name="com.customcompany.percustomssion.AUTHENTICATE_USER"/>
    <uses-percustomssion android:name="android.percustomssion.ACCESS_COARSE_LOCATION"/>
    <uses-percustomssion android:name="com.customcompany.percustomssion.LAUNCH_ACTIVITY"/>


    <!--<uses-percustomssion android:name="android.percustomssion.SET_DEBUG_APP"/>

    <percustomssion android:description="@string/percustomssion_launchActivity_description" android:label="@string/percustomssion_launchActivity_label" android:name="com.customcompany.percustomssion.LAUNCH_ACTIVITY" android:protectionLevel="signature"/>
    <percustomssion android:description="@string/percustomssion_authenticateUser_description" android:label="@string/percustomssion_authenticateUser_label" android:name="com.customcompany.percustomssion.AUTHENTICATE_USER" android:protectionLevel="signature"/>-->

    <uses-sdk android:customnSdkVersion="13" android:targetSdkVersion="13"/>

    <application android:allowBackup="false" android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon"  android:largeHeap="true" android:logo="@drawable/actionbarlogo" android:name="com.customcompany.application.CustomApplication" android:theme="@style/Theme.CustomAirline">
        <activity android:exported="true" android:name="com.customcompany.activities.ExternalLaunchActivity"  android:screenOrientation="portrait">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER"/>
                <action android:name="android.intent.action.MAIN"/>
            </intent-filter>
        </activity>
        <activity android:name="com.customcompany.activities.CustomAirlineActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="adjustPan"/>
        <activity android:name="com.customcompany.payment.CardPaymentActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="adjustPan"/>
        <activity android:name="com.customcompany.payment.CashPaymentActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="adjustPan"/>
        <activity android:name="com.customcompany.chooseflight.FlightDataActivity" android:screenOrientation="sensorPortait"/>
        <activity android:name="com.customcompany.login.LoginActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="stateAlwaysVisible|adjustResize"/>
        <activity android:name="com.customcompany.forms.FormEntryActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar"/>
        <activity android:configChanges="orientation|screenSize" android:name="com.customcompany.manual.reader.pdfreader.PDFReaderAct" android:theme="@style/Theme.CustomAirline.ActionBar"/>
        <activity android:configChanges="orientation"  android:name="com.customcompany.manual.reader.pdfreader.AndroidListViewActivity"/>
        <activity android:configChanges="orientation|screenSize"  android:name="com.customcompany.manual.CustomManualActivity" android:theme="@style/Theme.CustomAirline.ActionBar"/>
        <activity android:configChanges="orientation|screenSize" android:name="com.customcompany.manual.reader.genericreader.GenericReader" android:theme="@android:style/Theme.NoDisplay"/>
        <service android:enabled="true" android:exported="false" android:name="com.customcompany.service.ControlledReplicationService"/>
        <service android:enabled="true" android:exported="false" android:name="com.couchbase.android.CouchbaseService"/>
        <service android:enabled="true" android:exported="false" android:name="com.customcompany.service.LocalCouchService"/>
        <service android:enabled="true" android:exported="false" android:name="com.customcompany.ifs.discovery.InflightSyncService"/>
        <activity android:configChanges="orientation|screenSize" android:name="com.customcompany.manual.reader.htmlreader.HTMLReader" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="stateHidden|adjustResize|adjustPan"/>
        <activity android:name="com.customcompany.payment.PreOrderActivity" android:screenOrientation="sensorPortait" android:theme="@style/Theme.CustomAirline.ActionBar" android:windowSoftInputMode="adjustPan"/>
    </application>
</manifest>

Pom file

           <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <version>3.8.0</version>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>${proguard.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>manifestUpdate</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>manifest-update</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>alignApk</id>
                        <phase>package</phase>
                        <goals>
                            <goal>zipalign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <release>true</release>
                    <sign>
                        <debug>false</debug>
                    </sign>
                    <zipalign>
                        <skip>false</skip>
                        <verbose>false</verbose>
                        <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk
                        </inputApk>
                        <outputApk>
                            ${project.build.directory}/${project.artifactId}-${project.version}-signed-aligned.apk
                        </outputApk>
                    </zipalign>
                    <manifest>
                        <debuggable>false</debuggable>
                        <!-- note: below is set to false for testing. Feel free to use auto-increment
                            if you are sure about using auto-increment -->
                        <versionCodeAutoIncrement>false</versionCodeAutoIncrement>
                    </manifest>
                    <proguard>
                        <!-- Set the skip to false when making a proguard release -->
                        <skip>true</skip>
                        <config>${proguard.config}</config>
                        <jvmArguments>
                            <jvmArgument>-Xms512m</jvmArgument>
                            <jvmArgument>-Xmx1024m</jvmArgument>
                        </jvmArguments>
                    </proguard>
                    <manifestApplicationLabel>CrewApp-CD</manifestApplicationLabel>
                </configuration>
            </plugin>

I would like to control the name of the app and logo for it based on the maven profile I select to build the Android project. Is this a supported feature, if so , how do we do this?


回答1:


You can do that with the android-maven plugin (at least in version 3.80). The following is a blueprint for the profile in the pom:

<profile>
        <id>yourProfile</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>manifestUpdate</id>
                            <phase>process-resources</phase>
                            <goals>
                                <goal>manifest-update</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <manifestApplicationLabel>yourLabel</manifestApplicationLabel>
                        <manifestApplicationIcon>yourIcon</manifestApplicationIcon>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

For other parameters see the maven plugin.



来源:https://stackoverflow.com/questions/22040759/update-the-app-name-and-logo-based-on-the-maven-android-build-profile

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