Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename packages with android maven plugin

Tags:

android

maven

ant

As usual you stuck with maven when you try to make something non-standard.

I'm currently trying to rename my main application package for Android app to be able run different branded apps from same sources.

We are using android maven plugin and it's super hard to accomplish it.

  1. I was trying first easy way - use renameManifestPackage configuration. But this looks like not what I expected. Because resulted apk is not possible to install now.

  2. I tried second approach. Run ant on initialization phase to rename packages from sources/resources/tests/AndroidManifest.xml. This almost works if I skip tests. If not than Robolectric fails because it is using original manifest. If I wouldn't copy manifest and do replacement in original file everything works but I have now modified AndroidManifest and this breaks my working environment (IDE).

Does anyone have clear steps how to have package renaming and still have working environment?

UPD: The issue mentioned in point 1 was that I used wrong package name "devapp". It should contain at least one '.'. It's fixed by using "my.package.devapp". And installation passed successfully. But I can't install new app right now because:

Can't install because provider name my.package.app (in package my.package.devapp) is already used by my.package.live

I'm not sure what to do next. Going to deep more into apktool.

like image 557
Eugen Martynov Avatar asked Mar 01 '13 16:03

Eugen Martynov


2 Answers

I got it is working with 3.5.1 android maven plugin and next lines in configuration:

<renameManifestPackage>my.package.${environment}</renameManifestPackage>
<manifest>
    <providerAuthorities>
         <property>
             <name>my.package.provider.Provider1</name>
             <value>my.package.${environment}</value>
         </property>
         <property>
             <name>my.package.provider.Provider2</name>
             <value>my.package.${environment}.media</value>
         </property>
    </providerAuthorities>
</manifest>
like image 139
Eugen Martynov Avatar answered Nov 15 '22 04:11

Eugen Martynov


Prevent the AndroidManifest.xml from being overwritten

An issue with using the android-maven-plugin to change the AndroidManifest.xml file is that it can be committed to your SCM by mistake.

A new feature has been introduced since android-maven-plugin version 3.8.0 which gives you the opportunity to save the updated AndroidManifest.xml in another location.

Sample:

  <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>3.8.2</version>
    <extensions>true</extensions>
    <configuration>
      <renameManifestPackage>com.domain.android${environment}</renameManifestPackage>
      <updatedManifestFile>${project.build.directory}/AndroidManifest.xml</updatedManifestFile>
      <manifestApplicationLabel>Appname${environment}</manifestApplicationLabel>
      <manifest>
          <providerAuthorities>
               <property>
                   <name>com.domain.android.vc2.utility.SearchSuggestionsProvider</name>
                   <value>com.domain.android${environment}.searchsuggestionsprovider</value>
               </property>
               <property>
                   <name>com.domain.android.widget.VPWidgetDataProvider</name>
                   <value>com.domain.android${environment}.widget.provider</value>
               </property>
          </providerAuthorities>
      </manifest>
    </configuration>
    <executions>
      <execution>
        <id>update-manifest</id>
        <goals>
          <goal>manifest-update</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Then content in the element updatedManifestFile will result in a copy of the original AndroidManifest.xml file is created with this name and used for updates. Of course also for packaging of the apk.

By adding the property environment to your mvn command you can create different builds that installs beside each other on the same device.

 mvn clean package -Denvironment=.beta

More to read

This link explains this and more about the properties to the plugin:

http://jayway.github.io/maven-android-plugin/manifest-update-mojo.html#updatedManifestFile

like image 31
javabeangrinder Avatar answered Nov 15 '22 03:11

javabeangrinder