Saturday, December 15, 2012

How to Rename an android app without changing the identifier


How to rename an android app without changing the identifier


Blog Post 1




I'll start by 
explaining the blog
 posts I will do. I
 almost never will
 have posts about my
 life, they will
 instead focus
 around tech and
 programming.
 Programming in
 particular, is what I
 will write about
 here. Let's get
 started.



How to rename an android app without changing the identifier

OR using an IDE.

This was a question I had myself. I downloaded the source code to K-9 Mail, to work on my Epistol
 application, when I realized I really needed to change the name... But how? That was the question. It took
 me quite some time to figure it out, but I eventually discovered how to do it while on Stackoverflow.com.
 Great site by the way. 

 Now, I wanted to do this without an IDE, as Eclipse is really annoying when you try to import projects. I
 looked around the source, but I couldn't find it. But while on Stackoverflow I discovered the answer. It is
 AndroidManifest.xml file.

The file should look something like this,

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="17012"
    android:versionName="0.1" package="com.fsck.k9"
    >
    <uses-sdk
       android:minSdkVersion="7"
       android:targetSdkVersion="15"
       />
    <supports-screens
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:anyDensity="true"
    />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>

    <!-- Needed to mark a contact as contacted -->
    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>

.... It goes on...

Now at first, I thought it was the package that I wanted to change, but no. That just causes errors, instead
 you need to locate this key.

<application
        android:icon="@drawable/icon"
        android:label="@string/app_name"   <---Right there! That's what you want!
        android:name="K9"
        android:allowTaskReparenting="false"
        android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
        >



android:label= is what you want. Now, you can just change it to something like 

<application
        android:icon="@drawable/icon"
        android:label="New Name" 
        android:name="K9"
        android:allowTaskReparenting="false"
        android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
        >



That should work. But, instead, I used a xml file to store all my strings. That is the best way to do things,
 so I would suggest you do the same. Here's how. 
You will need to keep using the "@string/app_name" and then navigate to your string file. Usually, it is
 located somewhere around /res/values/strings.xml

So, that file should look something like:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- === App-specific strings ============================================================= -->

    <!-- This should make it easier for forks to change the branding -->

    <!-- Used in AndroidManifest.xml -->
    <string name="app_name">Epistol Mail</string>
    <string name="beta_app_name">Epistol Mail BETA</string>

    <string name="shortcuts_title">Epistol Accounts</string>
    <string name="unread_widget_label">Epistol Unread</string>

    <string name="remote_control_label">Epistol Mail remote control</string>
    <string name="remote_control_desc">Allows this application to control Epistol Mail activities and settings.</string>

Again, the is only part of it. But as you can see. The is a key labeled, <string name="app_name">

That is what you want to change, I changed mine to Epistol Mail, but the idea is the same. Now, some

 apps will use the string file for everything, like K-9 Mail, which was very nice. All I had to do was
 Find&Replace everything that says K-9 with Epistol. You could do something similar. 

That's pretty much it, happy coding!

1 comment:

Note: Only a member of this blog may post a comment.