Saturday, July 30, 2011

Android package renaming - no can do!

Well, it seem I can't avoid it and longer. I'm going to start preparing my app for upload to the Google Marketplace. I've actually done this before, for a client, but this is a bigger deal. First of all, it's my app. Plus, i've put several months of work into it, as opposed to the first, which was a much simpler and less customized app. There are also some wrinkles. For example, I'm planning to upload 5 paid apps in total, all identical except for the data they use.

This url,

http://developer.android.com/guide/publishing/publishing.html

Says - "If you've followed the steps outlined in Preparing to Publish,"

Which I'll go to now...

http://developer.android.com/guide/publishing/preparing.html

Preparing to Publish: A Checklist

Publishing an application means testing it, packaging it appropriately, and making it available to users of Android-powered mobile devices.

If you plan to publish your application for installation on Android-powered devices, there are several things you need to do, to get your application ready. This document highlights the significant checkpoints for preparing your application for a successful release.

If you will publish your application on Android Market, please also see Publishing on Android Market for specific preparation requirements for your application.


// ok


Before you consider your application ready for release:

Test your application extensively on an actual device

// ok, well, I have that covered.

Consider adding an End User License Agreement in your application

// Well, it's legalese. I don't want to take the time.

Consider adding licensing support

// Ok, I've done that, at least for one version.

Specify an icon and label in the application's manifest

// Ok.

Turn off logging and debugging and clean up data/files

// ok. Already did that.

Before you do the final compile of your application:

Version your application

// Ok, I have a version and version name - 1 and 1.0.


Obtain a suitable cryptographic key

// I've got that

Register for a Maps API Key, if your application is using MapView elements

// Don't have maps

Compile your application

// Ok

After you compile your application:

// Ok, I will do that

Sign your application

// Will do already have the code

Test your compiled application

// How to do that?

Ok, one complicating factor that's already coming up is I have will 10 apps, which are simply different versions of the same app. There will be 5 paid, which I'm working on now, and five free, which I'll work on later. They just have different data. I think the easiest wat to handle this is, instead of creating copies or branches, is just rename the package, and rename strings as necessary.

The package names will be

com.kanjisoft.jlpt5.free
.
.
.
com.kanjisoft.jlpt1.free

And

com.kanjisoft.jlpt5.full
.
.
.
com.kanjisoft.jlpt1.full

In the manifest, we only have to change the package name:

package="com.kanjisoft.jlpt4.full"

The strings that have to change are:

4

10000

And in the databaseHelper:

public static String DATABASE_PATH = "/data/.com.kanjisoft.jlpt/";

I could make my life easier by reading the level to derive the database path,

something like

AppState appState = (AppState) context.getApplicationContext();

boolean isFree = Utils.isFree((Context) appState);

String freeString = null;

if (isFree){
freeString = "free";
}
else {
freeString = "full";
}

//databasePath = "/data/.com.kanjisoft.jlpt/";

databasePath = "/data/.com.kanjisoft.jlpt" + appState.jlptLevel + "/" + freeString;


Ok. But, before we test this, we need to do the name change. I'm not a whole lotta happy about messing around with the package name, but it's for the good of mankind.

Ok here's what needs to change:

First, rename the package using eclipse...

Wow, that worked.

Ok, now change the package name in manifest:

package="com.kanjisoft.jlpt4.full"

And it's getting the dreaded R error.

[2011-07-29 22:29:04 - JlptQuizApp] (skipping hidden file '/Users/markdonaghue/Documents/workspace/JlptQuizApp/res/.DS_Store')
[2011-07-29 22:29:04 - JlptQuizApp] (skipping hidden file '/Users/markdonaghue/Documents/workspace/JlptQuizApp/res/drawable/.DS_Store')
[2011-07-29 22:29:04 - JlptQuizApp] ERROR: Unable to open class file /Users/markdonaghue/Documents/workspace/JlptQuizApp/gen/com/kanjisoft/jlpt4/full/R.java: No such file or directory
[2011-07-29 22:31:00 - JlptQuizApp] R.java was removed! Recreating R.java!
[2011-07-29 22:31:00 - JlptQuizApp] R.java was removed! Recreating R.java!

Ah, the old R import somehow snuck into the source code. I think I did the shift+crtl+O trick, which generated them. Let's get rid of them...

Clean and build - still no good. The R problem can be tricky.


If I rename it to a different name in the package, then refactor it to that name, it seems to compile. Maybe that's the trick - to change int the manifest first, then refactor the package.

Ok, let's see if it runs - it has that red exclamation point next to the project. What does that mean?

It means the project has errors, and needs to be recompiled, and we're back to square one.

I might need to delete the project from eclipse, and re-import it...

And - the refactor now had an error, and doesn't change back to the original name.

Let's revert.

Ulp - that doesn't work either. It may be because the rename affects how svn manages it.

Yes, I'm trying to revert to new content. Ok, rename the project - I can always pull it from svn.

Wait, it now exists in the renamed project under the original, plus the new name.

Ok, rename it back, delete the new package...ok, we're back in business.

I'll give this another go tomorrow...

No comments:

Post a Comment