0

I've got a problem that I can't seem to word correctly... So here's my best effort to explain it to your guys.

Scenario:

I'm working in Eclipse Helios. I've got two packages, let's say "com.android.HelloWorld" and "com.android.HelloWorldFree". I simply copied the original package, and took out features for the free version. I changed "all" references to be correct, and I even went through each file and searched for the phrase "HelloWorld" and replaced all instances I could find. I then pulled all then removed all JARs from BuildPath and then added them again to make sure there were no issues there. I then moved the free package out of the existing workspace into it's own to try to avoid any overlap.

Problem:

When I get a crash report in LogCat, I double click on the line that says for example:

"... com.android.HelloWorldFree.SceneManager$GameAd.init(SceneManager.java:2191)"

I'll click on the above line, thinking it will take me into my code where it crashed (HelloWorldFree.SceneManager$GameAd.init) however it takes me to the first version (HelloWorld.SceneManager$GameAd.init) that was created even though this package is not being launched at all. It will go to the proper line (2191) but in the file it opens it's completely commented section of my code? The original package (HelloWorld) ISN'T EVEN INSTALLED ON MY DEVICE! This happens here and there, and I'm not sure if it's me doing something wrong (obviously), or if it's Eclipse being it's retarded self...

Already Tried:

  1. Deleting R.java in HelloWorldFree
  2. Package -> Clean
  3. Build Package
  4. Remove all JARS and re-reference them...

So basically I can't even debug my project crashes? Now I'm not sure if it's crashing because of this, or if it's just referencing the wrong file in the crash report? Even though it says the right package and everything?

Many thanks to anyone who has ANY advice on where to go from here!

While-E
  • 1,527
  • 2
  • 20
  • 37
  • 1
    If you aren't using the project anymore, right click and Close it. Might correct the problem. – jprofitt Jan 17 '12 at 22:12
  • If you have same source in both projects, this issue happens. As jprofitt said, close the project which is not being used. – kosa Jan 17 '12 at 22:14
  • Not an answer to your question, but maybe the section about library projects in this article is an interesting read for you: http://developer.android.com/guide/developing/projects/index.html That way you can setup your code so that you do not have to copy/paste all code for two versions of the application. – Jan-Henk Jan 17 '12 at 23:12
  • Thanks guys, good info, I however did close the original project that wasn't in use anymore... apologies for not mentioning that in my original post. I guess with stuff like this, nothing should go without saying. This wasn't something I do often, but I'll definitely look at your link @Jan. If I figure out the problem specifically, I'll post back though. – While-E Jan 17 '12 at 23:15

1 Answers1

1

Well, 1st, you need to make sure that you are renaming correctly. And in the process of my answer, I will assume your package name for the paid version is com.example.HelloWorld and the free version is com.example.HelloWorldFree

Here's the way I do it (and let's say you made the paid version first):

  1. Dynamic "pro" code loading. See below.
  2. Delete the free version and delete contents on disk also (we're assuming you started with the paid version).
  3. Copy the paid version, the paste it.
  4. Right click on your package under the "src", then click Refactor > Rename. Append "Free" to the end of it.
  5. Uncheck all the checkboxes (like "Rename subpackages" and "Update References").
  6. Click "Ok".
  7. Open AndroidManifest.xml
  8. Change package="com.example.HelloWorld" to package="com.example.HelloWorldFree"
  9. Press CTRL+SHIFT+S (to save), then click "Yes".

Then clean the project. Make sure you have both the free version and the paid version uninstalled from your device by running adb uninstall com.example.HelloWorld and adb uninstall com.example.HelloWorldFree. Then install the app on your device.

Now, the "Dynamic 'pro' code loading". What I mean by this is changing your code in a way that does not require you to make ANY changes other than the package name before launching the free version.

What I do is I have a class as so:

public class M {

    public static boolean isPro(Context context){
        boolean hasPro;
        String pn = context.getPackageName();
        //Log.i(tag, "The package name is"+pn);
        if (pn.equals("com.example.HelloWorld")){
            hasPro = true;
        } else {
            hasPro = false;
        }

        return hasPro;
    }

}

And then before loading code that requires you to have the paid version, I do:

if (M.isPro(context)){
   //do some code
} else {
   //tell user to buy the pro version
}

And then anywhere that you references the string "com.example.HelloWorld" use context.getPackageName() instead.

The list at the top hopefully fixes your problem - since maybe you were just missing a step or something. Everything else just makes life a LOT easier.

Reed
  • 14,703
  • 8
  • 66
  • 110