I create a project with free and pro edition based productFlavors, and use different string resource file for different edition, the folders construction is cc.png.
If I change Build Variant in panel, the values in Android tab display two strings.xml(2), one is located main folder, another is located free or pro folder, you can see aa.png and bb.png.
I hope that all string resource files can be displayed together, it will display three string.xml(3), first is located main folder, sencond is located free folder, third is located pro folder. How can I do that ? Thanks!
CC.Png
AA.png
BB.png
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "info.dodata.messagecleanup"
minSdkVersion 9
targetSdkVersion 22
versionCode 7
versionName "1.07"
archivesBaseName = "MessageCleanup-V" + versionName
}
productFlavors {
free {
applicationId "info.dodata.messagecleanup"
buildConfigField "String", "AppName", "\"Message Cleanup\""
}
pro {
applicationId "info.dodata.messagecleanup.pro"
buildConfigField "String", "AppName", "\"Message Cleanup Pro\""
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
Unfortunately the Android project pane view does not support this behavior. The Android view was specifically designed to show the state of your project for a given build variant, not across all variants.
As you have already discovered, the easiest way to see your resources in all available configurations is to use the "project" view instead of the "Android" view.
You are also free to file a feature request on the Android issue tracker for the option to show the resources available across all variants.
You can define custom scopes within IntelliJ / Android Studio, that display specific folders/files:
You can then select that custom scope from the scope drop-down selector:
That said, I think the more efficient way of navigating between the string files is to hit the "Search Everywhere" hotkey, type "strings.xml", and select the one you want:
Related
I am working on updating an Android app using Android Studio 3. The previous versions where created using Android Studio 2.
When I build the last version using Android Studio 2 two separate APKs have been created, one for each product flavor I configured. Now in Android Studio 3 the "Generate Signed APK" dialog only offers a "combined" flavor which creates a single APK containing both flavors:
App Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.MyApp"
minSdkVersion 14
targetSdkVersion 26
versionCode 42
versionName "2.0.1"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "freemium", "free"
productFlavors {
MyApp {
dimension "freemium"
}
MyAppFree {
dimension "free"
applicationId 'com.example.MyApp.Free'
}
}
}
Select "Build/Generate Signed APK..." in Android Studio
Enter my keystore password and click Next
On the following page I can select the destination folder, the build type (release) and the flavors. While v2 offered both flavors here (MyApp and MyAppFree), v3 only offers MyApp-MyAppFree
app-MyApp-MyAppFree-release.apk is created instead of app-MyApp-release.apk and app-MyAppFree-release.apk
How to fix this?
Ok, the problem was caused by using different flavor dimensions for the two flavors. Gradle creates one assemble task for each dimension combination: MyAppMyAppFree in my case
I added the dimensions only to to silence the warning "All flavors must now belong to a named flavor dimension" when updating from Android Studio 2 to 3. Since I did not actually used the dimensions the solution was to simply use one dimension for both flavors:
flavorDimensions "default"
productFlavors {
MyApp {
dimension "default"
}
MyAppFree {
dimension "default"
applicationId 'com.example.MyApp.Free'
}
}
Getting started with the new android studio it seems very flexible but that usually brings a steep learning curve. Hoping to get some help with that here.
I've built an app and deployed it with this build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "me.test.simpleProject
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
signingConfigs {
release {
storeFile file("../my.keystore.jks")
storePassword System.getenv("and_ks_pw")
keyAlias System.getenv("and_ky_alias")
keyPassword System.getenv("and_k_pw")
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile project(":Library:lib_my_lib_a")
compile project(":Library:lib_my_lib_b")
compile project(":Library:lib_my_lib_c")
}
This works pretty well and once I learn the syntax it'll be much easier to use than the previous system.
Now my question.
I would like to basically add a few product flavors.
I currently use google analytics to track clicks, usage stats, simple things like that.
In the past [before android studio] typically distribute my apps in a free/ paid version.
I would like to create say build flavors for:
google play free
google play paid
amazon free
amazon paid
The code for these apps should be mostly identical but they cannot be since, for example adding links to google play in your amazon apps gets you in a bit of trouble over there. So I will need to have unique classes across the build flavors.
I was reading some docs and watching google talks about setting up the build flavors but I am a bit confused.
Can someone help me define the folder structure for this project?
current application structure
test/
.gradle/
.idea/
app/
app/build
app/libs <-- empty
app/src
app/.gitignore
app/app.iml
app/build.gradle
app/proguard-rules.pro
build/
gradle/
Library/lib_a
Library/lib_b
Library/lib_c
.gitignore
build.gradle
gradle.properties
gradlew
gradlew.bat
local.properties
settings.gradle
test.iml
Can I place the new folders anywhere and how do I link them up with grade to properly build the variants?
The first thing you should do, is add these flavors to your gradle script, inside the android section:
productFlavors {
googleFree {
applicationId = "com.your.app.gfree"
}
googlePaid {
applicationId = "com.your.app.gpaid"
}
amazonFree {
applicationId = "com.your.app.afree"
}
amazonPaid {
applicationId = "com.your.app.apaid"
}
}
Note that you can define different package names for your app if needed, as well as some additional properties. Full details: Gradle Plugin - Build Variants
At this point you will have three different concepts in your app now:
Build types: Debug and Release
Product flavors: googleFree, googlePaid, amazonFree and amazonPaid
Build variants: Combination of build types and flavors
googleFreeDebug
googleFreeRelease
googlePaidDebug
googlePaidRelease
amazonFreeDebug
amazonFreeRelease
amazonPaidDebug
amazonPaidRelease
Flavor Specific resources:
For defining resources, you should have:
app
src
main
java
res
googlePaid
java
res
googleFree
java
res
amazonPaid
java
res
amazonFree
java
res
With that structure in place, you can place all your shared stuff under main, while the flavor specific stuff would live on each flavor's folder. Then, when building a specific variant of your app, android and gradle will resolve the right resources for you. If you are interested in more details, see Resource Merging.
Once the flavors have been added to your build.gradle file, if you sync your project, Android Studio will be able to pick your build variants and you may select these from the IDE:
To use flavors in your app you should have a structure like this:
app
src
flavor1
java
res
flavor2
java
res
main
java
res
You have to define the flavors in the build.gradle:
productFlavors {
flavor1 {
//
}
flavor2 {
//
}
}
Then you can have different dependencies using:
dependencies {
releaseCompile
debugCompile
flavor1Compile
flavor1DegubCompile
}
For example:
dependencies {
freeCompile 'com.google.android.gms:play-services:7.5.0'
}
Android Studio 1.1 generated apk file (located # app/build/outputs/apk folder) contains the lib directory, and for every cpu type there exists a non-empty folder, like /x86. Each of these folder contain a libapp.so shared library that is around 5Kb in size per cpu.
I've searched the net and the only thing I found so far is this link from Intel https://software.intel.com/en-us/articles/building-native-android-apps-using-intelr-c-compiler-in-android-studio that shows how to change the default libapp.so to user-provided library.
So, I guess that this library (libapp.so) is somehow built by gradle.
In fact I do my own native library building, using ndk-build command line tool, and my libs are placed alongside that libapp.so. It's not causing any issues btw, but I feel that I'm losing the control over what is built and why.
Here's my humble build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
/**
* Path to *.so files
*/
sourceSets {
main {
jniLibs.srcDirs = ['src/main/libs']
jni.srcDirs = [] //disable automatic ndk-build
}
}
defaultConfig {
applicationId "com.sample.android"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
How can I disable this libapp.so being built?
defaultConfig {
ndk {
moduleName "yourSelfLib"
}
}
I try to make an application for multiple partners and for each partner a test and prod version. For each flavors I create a specific folder with res/values in it like the documentation said.
My gradle file look like this :
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileSdkVersion 14
buildToolsVersion "21.1.2"
defaultConfig {
versionCode 1
versionName 1
minSdkVersion 14
targetSdkVersion 19
}
productFlavors {
prodPARTNER1 {
applicationId "com.PARTNER1"
}
testPARTNER1 {
applicationId "com.PARTNER1.test"
}
prodPARTNER2{
applicationId "com.PARTNER2"
}
testPARTNER2{
applicationId "com.PARTNER2.test"
}
}
sourceSets {
testPARTNER2 {
res.srcDirs = ["testPARTNER2/res", "prodPARTNER2/res"]
}
}
}
dependencies {
compile project(':ViewPagerIndicatorLibrary')
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/jackson-annotations-2.2.3.jar')
compile files('libs/jackson-core-2.2.3.jar')
compile files('libs/jackson-databind-2.2.3.jar')
compile files('libs/urlimageviewhelper-1.0.4.jar')
}
I want for a test version to take res folder of the prod version (like this I not duplicate resources for both version) and merge it with the test version.
The problem is :
Error:Error: Duplicate resources:
C:\...prodPARTNER2\res\values\strings.xml:string/app_name, C:\...testPARTNER2\res\values\strings.xml:string/app_name
Any idea ? It's not possible to merge too res folder for the same flavors ?
EDIT : I use gradle v 1.1.0 and android studio v 1.1.0 too
Warning: this approach has changed a little bit on Android Plugin for Gradle 3.0.0
Use productFlavors for each partner app and define a build type test for test builds.
productFlavors {
partner1 {
applicationId "com.partner1"
}
partnerN {
applicationId "com.partnerN"
}
}
buildTypes {
debug {
// use defaults
}
release {
// the 'prod' version, use defaults
}
test {
// config as you want!
applicationIdSuffix ".test"
versionNameSuffix " Test"
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
}
You can use mix and match source folders as the Android Plug-in for Gradle shows:
To build each version of your app, the build system combines source code and resources from:
src/main/ - the main source directory (the default configuration common to all variants)
src/<buildType>/ - the source directory
src/<productFlavor>/ - the source directory
Edit: This user guide is another source of help: http://tools.android.com/tech-docs/new-build-system/user-guide
Edit 2: according to the link above:
Additional sourcesets are also created for each variants:
android.sourceSets.flavor1Debug
Location src/flavor1Debug/
android.sourceSets.flavor1Release
Location src/flavor1Release/
android.sourceSets.flavor2Debug
Location src/flavor2Debug/
android.sourceSets.flavor2Release
Location src/flavor2Release/
Then, you can use /src/partner1Test/ to define resources specifics to partner1 flavor AND Test build, that is a partner1Test build variant.
Problem: I want two product flavors, a FREE version with ads and a PRO version without ads.
Ads require Google Play with a min SDK of 9 so I set that for FREE but I want my pro version to have a min SDK of 8.
The build of the FREE version works but the build of PRO does not.
I am using (stable) Android Studio 1.1.0.
I setup a new project with a blank activity (Hello World example).
I then modified the build.gradle file (below) to include the two flavors and FREE-specific compile dependency and then modified the file structure to move the activity's java and layout xml files into the flavor structures. Thus, the project has the following file structure:
app\src\
free\
java\com\sample\adexample\MainActivity.java - This is Hello World.
res\layout\activity_main.xml - This is the Hello World layout.
res\values\strings.xml - Unique Hello World string for free version.
res\AndroidManifest.xml - This is a copy of the manifest in main.
main\
java\com\sample\adexample\ - empty
res\layout\ - empty
res\AndroidManifest.xml - This is the Hello World manifest.
pro\
java\com\sample\adexample\MainActivity.java - This is Hello World.
res\layout\activity_main.xml - This is the Hello World layout.
res\values\strings.xml - Unique Hello World string for free version.
res\AndroidManifest.xml - This is a copy of the manifest in main.
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.sample.adexample"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
pro {
applicationId "com.sample.adexample.pro"
minSdkVersion 8
versionName "1.0-Pro"
}
free {
applicationId "com.sample.adexample.free"
minSdkVersion 9
versionName "1.0-Free"
dependencies {
compile 'com.google.android.gms:play-services:6.+'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
Building the freeDebug flavor works fine.
But I get the following error when building proDebug:
:app:processProDebugManifest
C:\Users\Jeff\AndroidStudioProjects\AdExample\app\src\main\AndroidManifest.xml:0:0 Error:
uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library C:\Users\Jeff\AndroidStudioProjects\AdExample\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.5.87\AndroidManifest.xml
Suggestion: use tools:overrideLibrary="com.google.android.gms" to force usage
Is there a way to accomplish the requirements?
Thanks for your time.
Remove the dependencies closure from free. Move that compile 'com.google.android.gms:play-services:6.+' into your existing dependencies closure and make it be freeCompile rather than compile.
A prefix on the compile statement is how you make dependencies be tied to build variants rather than be used all the time the way compile is. So, a debugCompile would declare a dependency for only the debug build type, and freeCompile would declare a dependency for only the free product flavor.
AFAIK, this should work for multiple flavor dimensions, so if you had a dependency that was only relevant for the bird flavor (on one dimension) and the free flavor (on another dimension), you could use freeBirdCompile 'com.skynyrd.lynyrd:raised-lighter:1.0.0' to pull that in.