Build variables.

Is there an elegant way to set build variables that get inserted into the code?

For example in the build.sh set “amazon” or “google” so we know what store we are building for?

My issue is that the native.popup(“rateApp”) won’t work if a non-kindle user downloads the app from the amazon store.  I can’t use the device type, so I need a way of specifying a store on build.

You can set the target app store in Corona by adding the following metadata tag to your “AndroidManifest.xml” file…

\<manifest ...\> \<application ...\> \<meta-data android:name="targetedAppStore" android:value="amazon"/\> \</application\> \</manifest\>

The value string that you set will be taken as is.  Meaning if you make up your own store name, say “abc”, then our Lua API such as system.getInfo(“targetAppStore”) will return that string.

Unfortunately, there isn’t a simple “build variable” equivalent like in C/C++.  This is a common complaint in the native Android development world because this isn’t simple to set up.  The next best thing you’ve got is your “build.xml” where you can set up different build targets or set up ant properties to make the build do different things.  A common technique that I’ve seen in the native Android world is to set up multiple string resource files, each providing a different store name that the app will be targeting.  So, when you build for a particular store via ant, your ant’s build.xml would then copy one string resource file for the app store it is targeting just before it compiles the APK.  Your AndroidManifest.xml file can reference that string resource via the ‘@’ symbol, as documented by Google.

Or, you can keep it simple and just fork your application project for each app store you are targeting.  Some native Android developers do this too because they may include different libraries for different stores.  For example, if you are targeting the Amazon app store, then you may want to include their Amazon SDK if you want to leverage its features… but it wouldn’t make to include those libraries when targeting any other app store.  So, forking your app in this case actually keeps things much simpler.

The targetAppStore variable is perfect! Thanks.

My trick is that I split the build scripts in the android/ directory into amazon/ and google/ directories. So I have seperate build scripts, but one common Corona src directory.

I still want to handle everything from one codebase.

How do I set that inside of an Xcode build? Will it automatically be set?

Glad you got it working!

On iOS, Corona always returns “apple” for the app store.  It’s hard coded… because there is only one app store option in the iOS world.

Makes sense. Just wanted to make sure that was the behavior. Thanks.

You can set the target app store in Corona by adding the following metadata tag to your “AndroidManifest.xml” file…

\<manifest ...\> \<application ...\> \<meta-data android:name="targetedAppStore" android:value="amazon"/\> \</application\> \</manifest\>

The value string that you set will be taken as is.  Meaning if you make up your own store name, say “abc”, then our Lua API such as system.getInfo(“targetAppStore”) will return that string.

Unfortunately, there isn’t a simple “build variable” equivalent like in C/C++.  This is a common complaint in the native Android development world because this isn’t simple to set up.  The next best thing you’ve got is your “build.xml” where you can set up different build targets or set up ant properties to make the build do different things.  A common technique that I’ve seen in the native Android world is to set up multiple string resource files, each providing a different store name that the app will be targeting.  So, when you build for a particular store via ant, your ant’s build.xml would then copy one string resource file for the app store it is targeting just before it compiles the APK.  Your AndroidManifest.xml file can reference that string resource via the ‘@’ symbol, as documented by Google.

Or, you can keep it simple and just fork your application project for each app store you are targeting.  Some native Android developers do this too because they may include different libraries for different stores.  For example, if you are targeting the Amazon app store, then you may want to include their Amazon SDK if you want to leverage its features… but it wouldn’t make to include those libraries when targeting any other app store.  So, forking your app in this case actually keeps things much simpler.

The targetAppStore variable is perfect! Thanks.

My trick is that I split the build scripts in the android/ directory into amazon/ and google/ directories. So I have seperate build scripts, but one common Corona src directory.

I still want to handle everything from one codebase.

How do I set that inside of an Xcode build? Will it automatically be set?

Glad you got it working!

On iOS, Corona always returns “apple” for the app store.  It’s hard coded… because there is only one app store option in the iOS world.

Makes sense. Just wanted to make sure that was the behavior. Thanks.