3

I have a template app which can be easily reskinned changing config params according to a client's brand. When it comes to publishing on Google Play, I obviously need to change packagename on AndroidManifest.xml.

My question is: is that possible without changing folder names, so that I don't need to mess with the whole project structure?

ssantos
  • 16,001
  • 7
  • 50
  • 70
  • 1
    `applicationId` in gradle is what you want – David Medenjak Jan 21 '16 at 08:25
  • Thanks @DavidMedenjak. Unfortunately, this project has more than 5 years, does not use `gradle`, not to say `AndroidStudio` :( Is it possible to integrate `gradle` with an old eclipse project? – ssantos Jan 21 '16 at 08:30
  • 1
    It's far more easier to switch to Android Studio instead trying to integrate gradle to eclipse. – Christopher Jan 21 '16 at 08:32
  • Of course you can also change the packagename in Android Manifest. But you have to ensure that your services, activities, ... are declared with a fully qualified name, e.g. com.myapp.MainActivity instead of .MainActivity – Christopher Jan 21 '16 at 08:34
  • Thanks @Christopher, sorry to hear that :( Was looking for a way to automate the whole process, but I'm guessing the quickest way will be keeping manually exporting / renaming the whole project. – ssantos Jan 21 '16 at 08:34
  • Mmh that sounds promising, will give a try :) – ssantos Jan 21 '16 at 08:35
  • 1
    I strongly sugest you to moving AndroidStudio even if its old project, because in long term you will face less problems. For example in gradle you have solution for your problem out of the box. Just configure gradle build using unique applicationId per client. You will be forced to use AndroidStudio sooner or later. This is the right moment I guess because even if you manage to deal with this problem using renaming, it's easy to make mistakes during updates and your project will became messy – Karol Żygłowicz Jan 21 '16 at 08:45

4 Answers4

3

It's totally possible. In your AndroidManifest.xml you should change your package name according to your need, then all your activities and services should target the full path of your classes.

For instance if your application package name should be com.mybrand.myapp and your old java package name is com.myoldbrand.myoldapp your manifest should look like this :

<application
    android:allowBackup="true"
    android:icon="@mipmap/common_app_icon"
    android:label="@string/common_app_name"
    android:supportsRtl="true">

    <activity android:name="com.myoldbrand.myoldapp.MyActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

  • 2
    Thanks @JulesTréhorel, the only problem was that R class is generated on the new `packagename` path, so every import is broken. I finally solved it using a script to automatically *refactor* the import sentences. – ssantos Jan 22 '16 at 15:43
0

hi it's 4 years after your problem, I faced the same problem today, and here is my solution to the next one who face the problem

change com.example.your_app_name to what you need like com.companyname.your_app_name

you will find that in many places i know 4 of them

1.) src/profile/AndroidManifest.xml
2.) src/debug/AndroidManifest.xml
3.) src/main/AdroidManifest.xml
4.) build.gradle .
to find other places search about them with ((edit>>find>>find in path))
after changing them all it worked with me
Husamuldeen
  • 439
  • 1
  • 8
  • 21
-1

Android Studio has a really powerful refactor tool that allows you to rename the whole package structure on a easy way by also renaming all directories. You should not use different names in java packages and in your project directory tree, that will make your project pretty dirty.

Chus Muñoz
  • 120
  • 8
  • Unfortunately, moving to `AndroidStudio` is not a choice for me. I see your point regarding dirtiness, but I can face that for automation sake :) – ssantos Jan 21 '16 at 08:39
-1

Did you try this answer. It worked for me when I was working on Eclipse.

Community
  • 1
  • 1
1binary0
  • 93
  • 11