Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle: Android Studio inherit buildtype

I have in gradle (Android Studio) 4 build types

android {   buildTypes {      release { ... }      debug { ... }      kindle { ... }      kindle_debug { ... }   } } 

And I know, that my src folder can have for each build type one folder. So it ends up into

 src/   -- debug   -- kindle   -- kindle_debug   -- main // used for every project   -- release 

At the moment kindle is the same as release and kindle_debug is the same as debug.

How can I avoid to duplicate the src-folders? Is there a way to inherit from release and debug or have I to set the src-folders by myself in the build.gradle file?

Edit: One solution, that seems to work, is to set symlinks, but I want to use Mac OS and Windows OS and not every new user wants to set symlinks by them self.

Edit 2: I use now product flavors, because of that, I can have debug/release and with that google, amazon and samsung. That's the best solution for my purpose.

like image 872
mars3142 Avatar asked May 09 '14 08:05

mars3142


People also ask

What is Buildtype in gradle Android?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.

How do I get the current flavor in gradle?

There is no "current flavor". The Gradle build file is building an object model of the build process. It is not an interpreted script only being used once a build is underway and a "current flavor" is known.

How do I sync gradle with Android Studio?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.

How do I add Buildscript in build gradle?

If your build script needs to use external libraries, you can add them to the script's classpath in the build script itself. You do this using the buildscript() method, passing in a block which declares the build script classpath. The block passed to the buildscript() method configures a ScriptHandler instance.


2 Answers

You can inherit from build types like the following:

buildTypes {      release { ... }      debug { ... }       kindle {          initWith buildTypes.release          ...      }      kindle_debug {          initWith buildTypes.debug          ...      }   } 
like image 172
Marco RS Avatar answered Oct 04 '22 17:10

Marco RS


The answer may be a little late, but I had a similar problem and managed to solve this by doing the following:

android {     sourceSets {         kindle {             java.srcDirs = ["src/release/java", "src/main/java"]         }         kindle_debug {             java.srcDirs = ["src/debug/java", "src/main/java"]         }     } } 

If you add this to your build.gradle file, the kindle build type will only use java files from release and main folder and the kindle_debug build type will use debug and release folder.

Of course you could add the kindle folder or the kindle_debug folder:

java.srcDirs = ["src/kindle/java", "src/release/java", "src/main/java"] java.srcDirs = ["src/kindle_debug/java", "src/debug/java", "src/main/java"] 

but you may run into duplicate class errors.

like image 44
Patrick Dorn Avatar answered Oct 04 '22 17:10

Patrick Dorn