Can I somehow alias R in Android?

I have two Android applications that share 90% of their code with each other, and due to political reasons (I think also technical reasons) need to have separate package names (so they'll appear under different URLs in Google Play)

I use git with two branches for each app, and I sync the two branches manually before each release. When running a diff command of the two branches, a lot of my files are different when in reality the only thing that's different is the package name of the auto generated file R, so for the first application I have 15 files with

import pkg.name.one.R;

and for the other app

import pkg.name.two.R;

I want to somehow import R in the same way for both classes.

I tried wrapping R like so:

package thescene;

public class RWrapper {

    public class R extends pkg.name.one.R {}

}

(which would make RWrapper the only different file between these two branches in regards to the source or R) but alas R is a final class (and I'm not even sure this would've worked anyway)

So it there a way to somehow alias the R class in a way that would allow me to have the import pkg.name.one.R; / import pkg.name.two.R; replaced with a unified import statement?

I'm also open to other suggestions that would solve my syncing woes :)

Answers


Couldn't you modify RWrapper to make R a static field instead of a class? Your code would then access R via RWrapper.RClass...

Example

public class RWrapper
{
  public static pkg.name.one.R R;
}

and

public class RWrapper
{
  public static pkg.name.two.R R;
}

You'd access the R fields with:

RWrapper.R.<blah>

seggy had it almost right, but you need to expose each R.class individually. If the sub-module has it's own namespace then you can re-use the class name R and not need to modify anything in your sub-module.

package the.submodule.package;

public final class R {
public static the.app.package.R.string string;
public static the.app.package.R.drawable drawable;
public static the.app.package.R.id id;
//public static the.local.appPackage.R.anythingElse anythingElse;
}

Note: I'm not condoning sharing R across projects, but sometimes time constraints etc.


Need Your Help

How to generate a URL for ASP.NET MVC without string names

asp.net-mvc

How to generate a URL for ASP.NET MVC without string names? I.e. I have Index action in HomeController. Using strings I would go for

Mathematical modulus in c#

c# modulo

Is there a library function in c# for the mathematical modulus of a number - by this I specifically mean that a negative integer modulo a positive integer should yield a positive result.