android-studio,gradle,android-gradle,build.gradle,android-productflavors , Android studio gradle flavor dimensions build varients not working correctly


Android studio gradle flavor dimensions build varients not working correctly

Question:

Tag: android-studio,gradle,android-gradle,build.gradle,android-productflavors

I have two dimensions of an app, call then green and blue. There will only be these two dimensions but an unlimited number of product flavors. This is the way I'm setting it up in gradle

flavorDimensions "green", "blue"

productFlavors {

    one {

        applicationId "com.app.green.one"
        versionCode 1
        versionName "1.0.0.1";
        flavorDimension = "green"
    }
    two {
        applicationId "com.app.blue.two"
        versionCode 6
        versionName "1.0.1";
        flavorDimension = "blue"
    }

}

But then after i sync gradle, in the build variants tab all I see is oneTwoDebug and oneTwoRelease, where I should see greenOneDebug greenOneRelease, blueTwoDebug, blueTwoRelease

In theory I want to extend it to be something like this

one {

        applicationId "com.app.green.one"
        versionCode 1
        versionName "1.0.0.1";
        flavorDimension = "green"
    }
    two {
        applicationId "com.app.blue.two"
        versionCode 6
        versionName "1.0.1";
        flavorDimension = "blue"
    }

    three {

        applicationId "com.app.green.three"
        versionCode 1
        versionName "1.0.0.1";
        flavorDimension = "green"
    }
    four {
        applicationId "com.app.blue.four"
        versionCode 6
        versionName "1.0.1";
        flavorDimension = "blue"
    }

In this case dimensions represent the "type" of app, and then the flavors are more for organizations which can be added.

**EDIT I had the wrong set up for gradle as pointed out here is a more accurate depiction of what I have

flavorDimensions "type", "organization"

productFlavors {

    blue {
        applicationId "com.app.blue"
        flavorDimension = "type"
        versionCode 6
        versionName "1.0.1";
    }
    red {
        applicationId "com.app.red"
        flavorDimension = "type"
        versionCode 1
        versionName "1.0.0.1";

    }

    company1 {
        flavorDimension = "organization"
    }
    company2 {
        flavorDimension = "organization"
    }

}

So far this works, So I can create java source directories for toggling types, but what if I want organization specific config files, do I create java source dirs for each organization as well?


Answer:

I think you misunderstood the concept of flavorDimension.

A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant.

In your case, you must define one flavorDimension named "type" and another dimension named "organization". It will produce, for each flavor in the dimension "organization" all possible "type" (or the dual formulation : for each "type" it will produce a variant for each organization).

The flavor dimensions define the cartesian product that will be used to produce variants.


EDIT : I'll try to illustrate with pseudo-gradle code:

Let's define some "type" : bronze, silver and gold

Let's define some organizations : customerA, customerB, customerC

All those are productFlavors, but they belong to 2 different dimensions:

productFlavors {

    gold {
        ...
        flavorDimension = "type"
    }
    silver {
        ...
        flavorDimension = "type"
    }
    bronze {
         ...
        flavorDimension = "type"
    }

     customerA {
        ...
        flavorDimension = "organization"
    }
    customerB {
        ...
        flavorDimension = "organization"
    }
    customerC {
         ...
        flavorDimension = "organization"
    }

}

This config will produce 18 (3*3*2) variants (if you have the 2 standard build types : debug and release) :

gold-customerA-debug ; gold-customerA-release ; gold-customerB-debug ; gold-customerB-release ; gold-customerC-debug ; gold-customerC-release ;

silver-customerA-debug ; silver-customerA-release ; silver-customerB-debug ; silver-customerB-release ; silver-customerC-debug ; silver-customerC-release ;

... (the same for bronze)

Note that the name of the dimension is totally arbitrary and have no impact on variant names.

Flavor dimensions are very powerful, but if you use too much of them : it results in an exponential explosion of the number of variants (a post build clean-up task may be useful to delete useless or non-sense variant)


Related:


Twitter4j - cannot resolve method - setUsessl(boolean)


android,android-studio,twitter4j
I'm using twitter4j 4.0.3 core I have this code: public final class TwitterUtil { private RequestToken requestToken = null; private TwitterFactory twitterFactory = null; private Twitter twitter; private TwitterUtil() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(ConstantValues.TWITTER_CONSUMER_KEY); configurationBuilder.setOAuthConsumerSecret(ConstantValues.TWITTER_CONSUMER_SECRET); configurationBuilder.setUseSSL(true); Configuration configuration =...

PDF file path is incorrect [duplicate]


java,android,pdf,android-studio,filepath
This question already has an answer here: Android - Access file from assets \ PDF display 4 answers I want to open a PDF file in my application but something goes wrong everytime. Yeah , I watched many topics about it, however none of them helped me. Here are...

Android Studio plugin for capture Strings


android,string,android-studio
I'm searching a plugin for Android Studio that help me catch the Strings in my APP, I don't use the recomendations of the Android and make my APP using Strings hardcoded. How do you capture the Strings of codes of automatic way? [I've searched in the google (web) but I...

How to determine Android Full SDK Download size?


android,android-studio,android-sdk-tools
I'm asked to report Download size of Full Android SDK (Not Disk Size). On Disk : 49GB On Network (Downloaded Zip Files): ?GB Installed: Windows 7 x64 machine Tools till 24.3.1 Tool preview channel Android M Android API (22, 21,20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,...

Android Studio: cannot upgrade google play services


android,google-maps,android-studio,google-play-services,google-play-developer-api
I have tried download the latest version on the sdk manager, but is still not working. I have seen other posts telling users to enter the following... compile 'com.google.android.gms:play-services:4.2.+' I do not understand where to enter it. I tried in the terminal feature of the android studio but it gives...

how to add menu items to action bar in more than 30 activities


android,android-activity,android-studio,menu,menuitem
I have created an app in android studio that has more than 30 activities .I created menu items in some activities by adding them in individual menu files and they worked fine . But the problem is that it is a real headache to add all the menu items in...

Can't migrating AndroidManifest.xml file to Android Studio?


android,android-studio
When i try to migrating Eclipse ADT project to Android Studio using "Import project (Eclipse ADT, Gradle, etc.)" then selecting project root folder and then third window gives me error like this C:\Users\Tsomone\workspace\cims-android-app-new\AndroidManifest.xml: Invalid XML file: C:\Users\Tsomone\workspace\cims-android-app-new\AndroidManifest.xml: Premature end of file. and when i try to click Finish, it shows...

getView method causing NullPointerException


java,android,android-studio
I'm getting a NullPointerException, when I'm trying to get some image from database I think my getter and setter method is wrong, any help is much appreciated. This is my Activity public class ViewMoreDetailsImages extends Activity{ ProgressBar progressbar_01; ListView lv_images; ImageAdapter imageAdapter; List<ImageInformation> imageInformationList = new ArrayList<ImageInformation>(); @Override protected void...

Android device monitor seems to miss crashes


android,android-studio,logcat,android-logcat
At seemingly random occasions it looks like Log cat in Device monitor bundled with Android studio misses error messages. I have an app that crashed on different errors, Index out of bounds to mention one. At some occasions this crash was shown in the log, at other occasions it showed...

Android _ failed for task ':app:packageAllDebugClassesForMultiDex' _ AbstractDateTime.class?


android,android-studio
My Project was working fine, when I have added bellow code in my project get me error, I add : compile 'joda-time:joda-time:2.7' compile 'net.danlew:android.joda:2.8.0' Here is my build.gradle : apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "us.app.recyclerview_multiselect" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0"...

Error execute studio.sh unrecognized vm option 'MaxPermSize=350m' on Ubuntu 14.04


ubuntu,android-studio,ubuntu-14.04
Error to Execute/Install studio.sh on Ubuntu: [email protected]:~$ cd android-studio/bin [email protected]:~/android-studio/bin$ ./studio.sh Unrecognized VM option 'MaxPermSize=350m' Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. And with some knowledge after searching on search engines, I open the studio.vmoptions file in edit mode and...

Can I replace ActionBarActivity with AppCompatActivity in a Tabbed Activity in Android Studio?


android-studio
The following Tabbed Activity is created by Android Studio 1.2.2 Wizard, it works well in API 9, but someboyd told me that ActionBarActivity is deprecated, so I hope to replace public class MainActivity extends ActionBarActivity implements ActionBar.TabListener with public class MainActivity extends AppCompatActivity implements ActionBar.TabListener , and stay all other...

Countdown Timer Notification


android,android-activity,android-studio,background,countdowntimer
I'm begginer in Android programming, I have to do a CountdownTimer that starts from a number selected by the user using a two number pickers (one for Hours and other for minutes). The characteristics must be: -The CountdownTimer must work in background and notify the user when it arrives to...

How to set max line length in Android Studio code editor?


android-studio
How can I set a maximum length for Android Studio's code editor, or may be set a word wrap? In my Android Studio, no matter how long a statement I type on a single line, it never automatically goes to the next line, but rather a horizontal scroll bar appears....

Android build project error trying to build apps > 65K (65536) methods


android,android-studio,gradle,build,android-gradle
I have added these two new dependencies in my build.gradle compile 'com.android.support:appcompat-v7:22.2.0' compile 'com.android.support:design:22.2.0' And right now, I can't build my project because I've got an error. I have found information about the error and the solution that I have found says that I have to add ... compile 'com.parse.bolts:bolts-android:1.+'...

Using ant.replace in gradle


replace,ant,gradle
I want to use ant's replace task to replace token in one of the files like this: version.txt version.number=${versionNumber} build.gradle task writeVersion { ant.replace { file 'version.txt' token 'versionNumber' value '1.0.0' } } but it is giving me following error :- A problem occurred evaluating root project '1.01-Exercise-RunYourFirstTask'. > replace...

what is gradle missing to map hibernate?


java,hibernate,gradle
I have unittest to my java project. My code uses hibernate. When i run the test using junit - everything passes. When I run the test using gradle - I get a mapping error: Caused by: org.hibernate.MappingException: Unknown entity: linqmap.users.interfaces.model.UserRecord and the class: @Entity @Table(name = "users") public class UserRecord...

Cant start developing for android


android,android-studio
I have an app on iOS and now i need an android version. BUT I CANT. I downloaded android studio, downloaded everything from SDK manager, did everything for a basic project. But... Everything i use is deprecated. Tried making tabbed application... ActionBarActivity deprecated, every other thing i trie is deprecated......

If I change ID of an element in Android Studio, how do I carry on this change throughout the code?


android,android-studio
For example, say I'm using a relative layout and a lot of views are centered around a TextView with ID of TextView. If I change this ID to TextView1, the other elements referencing it all break. How can I change the ID so that the changes are carried out? Thanks...

app crashes with no input while using Edittext in android studio


java,android-studio,android-edittext
I am having this issue with Edittext in android studio.The app works fine but app crashes with no input Here is the java code public void onButtonClick (View v) { int num1,num2,sum; EditText e1 = (EditText)findViewById(R.id.num1); EditText e2 = (EditText)findViewById(R.id.num2); TextView t1 = (TextView)findViewById(R.id.sum); num1 = Integer.parseInt(e1.getText().toString()); num2 = Integer.parseInt(e2.getText().toString());...

Unexpected Token Error in Android Studio


android,android-studio
package com.hello_world.helloworld; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.util.log; public class HelloWorld extends AppCompatActivity { private static final String TAG - "My Message"; Another error it says is that Private field 'TAG' is never used. I am unsure why i am getting these errors and I need...

Cannot resolve symbols setAdapter and AttachToListView in Android Studio


android,android-studio
I was attaching the list view to FAB, but Android Studio is showing the following error: cannot resolve symbol at setAdapter and AttachToListView methods I tried rebuilding and closing and reopening the project. Code: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } String[]...

PNG transparent backgrounds appearing black when using Android Studio


android,android-studio,png,adt,android-drawable
The social icons below (for fb, twitter, mail and share) are circular PNGs with transparent backgrounds. When I use the code and exact same images in Eclipse, I get transparent background but when build and run with Android Studio, I get black backgrounds. See details below. Images are the same....

Gradle Exec : Why it is not running in configuration phase?


gradle,exec,mkdir
Here is my: build.gradle task makeDirectoryStructure(type:Exec){ description 'Creates directory structure .' commandLine 'mkdir' args '-p' ,'top_dir/sub_dir_1/sub_dir_2' println "This line is printed in configuration phase." } Now, since I haven't used '<<' or< 'doFirst/doLast', I expect mkdir to be executed in configuration phase i.e. whenever the build script is compiled. For...

How to put Like function under an image and save the “Liked” status?


java,android,android-studio,imageview,sharedpreferences
I'm trying to figure out how to put a "Like function" to a few local stored images and remember the app that the user liked those images. Let me explain: I want the user to be able to press "Like" under the image he likes. This means the "Liked" status...

Huge unusable font size in Android Studio


android,android-studio,fonts
As the title states, I've inadvertently set the font size to something gargantuan in Android studio and it's now totally unusable. At most I see the tops of a few letters once the program loads, so I can't even get back into the options to reduce the font size. Looking...

populating a text view in an android Fragment from a text file in /res/raw


java,android,android-fragments,android-studio
I am attempting to populate an textview in an android fragment. I am having no luck at all as the fragment is blank. I know I am fundamentally missing something. I have read the docs on fragments and I am still confused. Below is my code for one of the...

Gradle Jar structure is different than the real project structure


java,jar,gradle,build
I'm trying to build my project with gradle but for some reason the resources are put on a different level than their real level. Here's the build: apply plugin: 'java' version = '1.1' archivesBaseName = 'DesktopOmegle' repositories { //mavenCentral() maven { url 'http://oss.sonatype.org/content/repositories/snapshots/' url "http://repo1.maven.org/maven2" } } dependencies { compile...

Android Studio manifest Errors


java,android,android-studio
Could anyone please me as when ever I try to run my app I get errors in the manifest file such as the followig five errors below. Error:(2) No resource identifier found for attribute 'versioncode' in package 'android' Error:(2) No resource identifier found for attribute 'versionname' in package 'android' Error:(9)...

Trouble implementing android_serialport_api into my own application


android,android-studio,serial-port,embedded-linux,beagleboneblack
I am currently working on an embedded system for my company that runs the android 4.2 OS (from TI bbb source) on the Beaglebone black. I have been tasked with setting up communication with the serial port (UART). I have been able to configure the serial port and run the...

gradle execute task after build


gradle,build.gradle
I am using the build in gradle. My build.gradle file like this: project('a'){ apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'application' buildDir = 'build' [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' repositories { mavenCentral() } dependencies { compile 'org.slf4j:slf4j-api:1.7.7' } } When I input the gradle build in the command, I want...

Android studio gradle flavor dimensions build varients not working correctly


android-studio,gradle,android-gradle,build.gradle,android-productflavors
I have two dimensions of an app, call then green and blue. There will only be these two dimensions but an unlimited number of product flavors. This is the way I'm setting it up in gradle flavorDimensions "green", "blue" productFlavors { one { applicationId "com.app.green.one" versionCode 1 versionName "1.0.0.1"; flavorDimension...

How to download a library dependence on gradle for external use?


cordova,android-studio,gradle,android-gradle,cordova-plugins
I have a project on PhoneGap and I am trying to build a plugin to use a FilePicker library. So, I build one Android Studio Project and I have it working. So, right now, that I know that I know how to do it, I just need to know how...

Gradle multi-project custom build.gradle file name


gradle,build,multi-project
I have a multi-project Gradle build, which is currently configured through a single build.gradle file. There are over 70 modules in this project, and the single (gigantic) build.gradle file has become cumbersome to use, so I'd like to split it into small per-module buildscript files. Now, I don't want to...

Duplicate entry for class in gradle


java,android,android-studio,gradle
I am trying to implement ken burns view in android studio in my app, i have importted the folder which contains its classes, but gradle gives me this error Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry: com/flaviofaria/kenburnsview/MathUtils.class Here is my build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 21...

How to use Library from GitHub in android App


android,github,gradle,libraries
I downloaded this library to use in my app, however, I can't get Android Studio to do the gradle build now. Anytime I try, I get "error:configuration with name 'default' not found". I've tried several other StackOverflow answers, but I still can't compile. My dependencies (from build.gradle Module: app) dependencies...

Paid and Free versions of android app


android,gradle,android-version
I am wondering what is the best way to have two different versions of an android app. I would like to have version of my app with ads and one without ads (the paid one). What is the easiest way to achieve this ? I have found something called version...

Close module in android studio


android,eclipse,android-studio
in eclipse there is simple option to close or open project. How can I do it in android studio to close and open module without import it and delete each time?

Use higher API level in android with an external library


java,android,api,android-studio,material-design
Would it be possible to import an external library (.jar file) in an android project containing the features of API level 21, and then use them in my application with a minimum sdk version set to say like 17? I'm really into Matierial Design but as Google states, "To use...

Having problems while trying to delete single rows from a custom ToDo list?


android,android-fragments,checkbox,android-studio
I want to delete selected rows from a todo list by clicking on the checkbox and deleting them trough the delete button, for that I am within my custom adapter setting a setOnCheckedChangeListener on my checkbox and setOnClickListener on my delete button, now keep in mind that the delete button...

Android Studio and gradle


android,android-studio,gradle
I tried importing Xabber ( GitHub ) within Android Studio , I did the git init etc . Now I find that I can start the app for that problem Gradle , I've looked everywhere , but could not find anything that would work .. The problem is: Error:Execution failed...

Android - Custom Home Application Doesn't Appear When Click Home Button


android,android-studio
I'am using Android Studio and I have developed an Home Application by adding <activity android:windowSoftInputMode="stateAlwaysHidden" android:screenOrientation="landscape" android:launchMode="singleInstance" android:stateNotNeeded="true" android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.DEFAULT" /> <category...

Error:(12) No resource identifier found for attribute 'scalteType' in package 'android'


android,android-studio
Getting error messages when running an app on debug mode during the Gradle Build in Android Studio. This is the error message: Information:Gradle tasks [:app:assembleDebug] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72211Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42211Library UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig...

Gradle Assemble Debug is Successful But Does Not Work [duplicate]


android,command-line,gradle
This question already has an answer here: Why won't gradle run from within a jenkins job 2 answers After following instructions here: http://developer.android.com/tools/building/building-cmdline.html apparently you're supposed to chmod +x gradlew then ./gradlew assembleDebug which leads to the following output: /gradlew assembleDebug :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72200Library...

Make Robolectric run test for the current build type only


android-studio,robolectric
I'm using Robolectric alongside Android Studio (v 1.2.2) classpath 'com.android.tools.build:gradle:1.2.3' buildToolsVersion "21.1.2" testCompile 'org.robolectric:robolectric:3.0-rc3' My project contains 4 build types. In spite of having debug build type selected in the "Build Variants" window, Robolectric tests every declared build type (4 times). Is it an expected behavior? How can I narrow...