Sethu
Sethu

Reputation: 566

Android Compile Time directive

I have an android application with different flavours.What I mean by flavours is that they differ only in their application name,icon and a url that webview in the application uses.

What I have now: Application 1 with app_name1 and icon1: { Code... myWebview.loadUrl(url1); code.. } Application 2 with app_name2 and icon2: { SameCode... myWebview.loadUrl(url2) Samecode.. }

What I would like to have :

Application(pick the application name and icon from build parameter): { Code .. myWebview.loadUrl(pick the url from build parameter) Code.. }

Is this possible? This would be so good to have as I am manually copying any change that i do in either of the projects to the other and I am scared about how I would handle more than 2 "flavours".

Upvotes: 0

Views: 979

Answers (2)

Robert Tupelo-Schneck
Robert Tupelo-Schneck

Reputation: 10543

You probably want to take a look at Library Projects. See for instance this blog post:

Library Projects allow you to share some whole parts of your applications, resources included. The main and immediate use is to create several versions of the same application.

Upvotes: 2

Robert Tupelo-Schneck
Robert Tupelo-Schneck

Reputation: 10543

You should in any case be using resources to refer to these things. So e.g

<application android:label="@string:app_name" android:icon="@drawable:icon">

in your AndroidManifest.xml, and

String rl = getString(R.string.url);

in your code.

Then you simply have to swap in the right res/values/strings.xml and res/drawable/icon.png, and change the name of your final apk.

Upvotes: 0

Related Questions