Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing android plugins from gradle and gradle-experimental

Is there any way or workarounds or just hints to make plugins from gradle and gradle-experimental working together?

For example to mix those two versions:

com.android.tools.build:gradle:1.3.1
com.android.tools.build:gradle-experimental:0.3.0-alpha4

I have an existing project which uses some external plugins (app/build.gradle):

apply plugin: 'com.android.model.application'
apply plugin: 'com.android.databinding'
apply plugin: 'com.jakewharton.hugo'

in my root build.gradle I have:

com.android.tools.build:gradle-experimental:0.3.0-alpha4

Issues which I have:

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.databinding']
   > java.lang.NullPointerException (no error message)

or

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.jakewharton.hugo']
   > 'android' or 'android-library' plugin required.

Without other plugins my project works fine (I have Android Library with some NDK code which is called from my main project. Problem occurs when I add mentioned plugins on any others.

And the question is - is it a gradle-experimental issue or issue of each plugin (hugo, databinding, apt, probably much more).

Or maybe you have any hints if there is any other way to have app with current stable gradle plugin and library (with NDK code) which uses gradle-experimental?

What I want to avoid is a dealing with *.mk files and (as full as possible) Android Studio support. Bigger picture is to prepare .aar library with NDK code (just simple computation) which will be able to plug in to existing projects.

like image 721
froger_mcs Avatar asked Nov 03 '15 21:11

froger_mcs


People also ask

Which are the two types of plugins in Gradle?

There are two general types of plugins in Gradle, binary plugins and script plugins.

What is the use of Buildscript in Gradle?

buildscript: This block is used to configure the repositories and dependencies for Gradle. dependencies: This block in buildscript is used to configure dependencies that the Gradle needs to build during the project.

How do I add plugins to Gradle?

Put the source of the plugin directly into the build. gradle file. One big advantage of this approach is that the class is automatically compiled and added to the classpath of the build script without you configuring anything. The disadvantage is that the plugin cannot be used in another module.

What is buildSrc in Gradle?

buildSrc is a directory at the Gradle project root, which can contain our build logic. This allows us to use the Kotlin DSL to write our custom build code with very little configuration and share this logic across the whole project.


1 Answers

I've been able to mix gradle stable and -experimental android plugins without any issues by using recent versions in my project.

You should be able to define both dependencies inside your project's build.gradle file:

dependencies {
    classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha7'
    classpath 'com.android.tools.build:gradle:1.4.0-beta6'
}

and then either use apply com.android.(application|library) or com.android.model.(application|library) from your various module's build.gradle files.

like image 140
ph0b Avatar answered Oct 02 '22 05:10

ph0b