I have a file, res/xml/analytics_tracker.xml that stores my google analytics variables. I want to use different variables in my release vs debug builds.
So I have main/xml/analytics_tracker.xml (has maybe 6 xml-elements) & release/xml/analytics_tracker.xml (1 xml-element).
I decompiled my release apk via apktool and looked at the analytics_tracker.xml file. It only had the 1 element from the release xml file.
Shouldn't it merge the two xml files into one?
Normally if you want to have different debug and release versions of files, you would have a debug version in separate debug/.... folder, and release version in main/.... folder, at least this is how it's always in my projects. If it can's find a separate folder for a build type, it takes main/... version.
In your case I guess it found a release/.... version of your analytics_tracker file and used only it.
Here you can find the official doc about Resource Merging with gradle.
You can find the reason of your issue.
The priority order is the following:
BuildType -> Flavor -> main -> Dependencies.
This means that if a resource is declared in both the Build Type and in >main, the one from Build Type will be selected.
Related
I have 3 jar files in my Android project's app/libs folder:
api-dev.jar
api-qa.jar
api-prod.jar
I want to use api-dev.jar when I work on the app in the studio (default), build a version of the app using api-qa.jar which will be tested by the QA team, then release the production app with api-prod.jar.
How should I do?
So far I read that I should add a
configurations {
qaCompile
...
}
element to app/build.gradle and use
android {
buildTypes {
...
qa {
...
}
}
}
to define the builds.
I don't know how to point to the appropriate libs/dependencies, I don't know how to make one the default one either, especially in my case where the default one is not the one for the production release...
Also if the API requires a specific key for dev, qa and prod, how do I set it up?
By the way the features are exactly the same between the different builds, the user experience is exactly the same, it's why I want to use builds, not flavors.
Check this out - Add dependency to specific productFlavor and buildType in gradle
Add you jars to the libs directory
Create a build type and product flavor
Use the name to create a specific compile command
Use that to specify your jar file in the libs directory
I've got problem with very simple application. APK size is now 3 MB, but it contains a lot of useless for me files (I think that source of this files is Support Library). In my application I don't use any images, but all drawable directories contains a lot of icons, buttons, etc. Is it possible to delete this images by any rule in gradle or other method? I use Android Studio.
Already I added to build.gradle information about languages to include in APK. I had in Hello World 80 languages before it.
Screen of files:
The Gradle build system for Android supports "resource shrinking": the automatic removal of resources that are unused, at build time, in the packaged app. In addition to removing resources in your project that are not actually needed at runtime, this also removes resources from libraries you are depending on if they are not actually needed by your application.
To enable this add the line shrinkResources true in your gradle file.
android {
...
buildTypes {
release {
shrinkResources true
}
}
}
Check the official documentation here,
http://tools.android.com/tech-docs/new-build-system/resource-shrinking
is there a simple way to have installed two version of the app on the same android Phone?
Im updating a old web app to a native android app. For testing purpose it would be great if we could have both installed at the same time on the same device.
It would be great to rename the update just temporary.
If I rename the package name in the AndroidManifest, then also R will be renamed and I have to reorganize the imports etc.
Is it possible to do a simple rename only somewhere in the AndroidManifest without changing a single line of code (even not with eclipse / android studio refactoring mechanism).
I have tried to mark my native app as library project and to include it in a new Android Project with another package name. But I will get trouble with this approach, for instance with actionbar sherlock:
Unable to execute dex: Multiple dex files define Lcom/actionbarsherlock/R$attr;
Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/actionbarsherlock/R$attr;
If you are using new gradle build system you could create new build type and then just add packageNameSuffixto it. This will add suffix to your package name but everything else stays the same.
buildTypes {
debug {
packageNameSuffix ".debug"
}
}
There is an easy way if you want to do it temporarily. You need to modify the AndroidManifest.xml file.
Find the line that looks like this:
manifest package="com.example.myapp"
and change it to something like:
"com.example.myapp.debug"
AFAIK there is no way other than changing the application package name, but it's fairly easy.
In Eclipse, right-click your project and select Android Tools > Rename Application Package.
I am having two versions of my android project (release and debug). They both are sharing the same source files. I want the debug version to be intact when we checkin any changes for release build.
It is not working as we cant have 2 different manifest files for it and if we make change in manifest, it will affect both the projects and keep them out of sync.
Is there any way we can have different build configurations for same project?
Please advise.
Thanks
If you don't want to impact the debug app when changing the release source files you'll have to use different source files. Having different build files or configuration will not help.
Gradle apps use at least 3 source folders.
src/main/... is used by all variants
src/debug/... is used by the debug variant
src/release/... is used by the release variant
To do a change that only impact the release variant, just edit code in src/release/.... This can contain a manifest, res, java code, etc...
That said I'm not why you don't want to change the debug version when changing the release version. The whole point of the debug version is to be the same as the release, except debuggable. The different source folders above should only be used for minor things (like enabling/disabling log output for instance). Making both versions different in bigger ways is not recommended.
I have several options - both in code and in the manifest file - that I would like to easily toggle on and off based on whether it's a debug build or release build.
What's the best way to handle things like this in an Android application?
You could use properties files, e.g. one for prod and one for dev. Then you could create an Ant script with two targets, a prod build and a dev build, where the appropriate properties file is copied prior to the APK being built. Make sure that the properties files are copied using the same name, then you can access the deployed one, irrespective of the environment you built for.
In addition to what Tyler mentioned, if you are looking at including optional code in case it is a Debug and not having that code if its a release, then you could look at using the BuildConfig file that is generated by the ADT.
As per the docs: " Added a feature that allows you to run some code only in debug mode. Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions such as outputting debug logs."
You will find this file in the Project/gen folder, the same place where the R.java is generated.
Now with Android Studio and Gradle it is easy to do this using the auto generated flag BuildConfig.DEBUG. Like:
if (BuildConfig.DEBUG) {
// Debug code
} else {
// Resease code
}