How to use the Renderscript Support Library with Gradle

Using Android Studio: Add the following values to build.gradle for android gradle plugin v0.14+ android { … defaultConfig { … renderscriptTargetApi 19 renderscriptSupportModeEnabled true } … } For older versions of the android gradle plugin v0.13.3 and below android { … defaultConfig { … renderscriptTargetApi 19 renderscriptSupportMode true } … } Once that is done, … Read more

How to change the Android app package name when assembling with Gradle?

As a simpler alternative to using product flavours as in Ethan’s answer, you can also customise build types. How to choose between the approaches: If you need different package names to be able to have both debug and release apks installed on a device, then use the build type approach below, as Gradle plugin docs … Read more

Android Studio: Plugin with id ‘android-library’ not found

Instruct Gradle to download Android plugin from Maven Central repository. You do it by pasting the following code at the beginning of the Gradle build file: buildscript { repositories { mavenCentral() } dependencies { classpath ‘com.android.tools.build:gradle:1.1.1’ } } Replace version string 1.0.+ with the latest version. Released versions of Gradle plugin can be found in … Read more

Run task before compilation using Android Gradle plugin

Apparently, the android plugin doesn’t add a compileJava task (like the java plugin would). You can check which tasks are available with gradle tasks –all, and pick the right one for your (otherwise correct) dependency declaration. EDIT: Apparently, the android plugin defers creation of tasks in such a way that they can’t be accessed eagerly … Read more

How to define different dependencies for different product flavors

To define a flavor specific dependency you can use proCompile instead of compile in your dependency section. When you run gradle properties you get an overview of automatic created configurations. The correct build file looks like this: buildscript { repositories { mavenCentral() } dependencies { classpath ‘com.android.tools.build:gradle:1.2.3’ } } apply plugin: ‘com.android.application’ repositories { mavenCentral() … Read more

How to configure gradle to work “offline” (using cached dependencies)

Gradle does a good job of avoiding re-downloading artifacts, but you can pass –offline to Gradle to prevent from accessing the network during builds. e.g. gradle –offline build If it needs something from the network that it doesn’t have, instead of attempting to fetch it, your build will fail.