Extract common methods from Gradle build script

Building on Peter’s answer, this is how I export my methods: Content of helpers/common-methods.gradle: // Define methods as usual def commonMethod1(param) { return true } def commonMethod2(param) { return true } // Export methods by turning them into closures ext { commonMethod1 = this.&commonMethod1 otherNameForMethod2 = this.&commonMethod2 } And this is how I use those … Read more

In Gradle, how do I declare common dependencies in a single place?

You can declare common dependencies in a parent script: ext.libraries = [ // Groovy map literal spring_core: “org.springframework:spring-core:3.1”, junit: “junit:junit:4.10” ] From a child script, you can then use the dependency declarations like so: dependencies { compile libraries.spring_core testCompile libraries.junit } To share dependency declarations with advanced configuration options, you can use DependencyHandler.create: libraries = … Read more

How to use my own Android.mk file with Android Studio

yes, by default the gradle android plugin regenerates and uses its own Android.mk file to compile your sources. You can deactivate this and use your own Android.mk file instead, by setting this inside your build.gradle configuration file: import org.apache.tools.ant.taskdefs.condition.Os … android { … sourceSets.main { jniLibs.srcDir ‘src/main/libs’ //set libs as .so’s location instead of jniLibs … 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

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?

You can add below 2 lines into your gradle.properties file: android.useAndroidX=true android.enableJetifier=true Note to check, to not repeat any line that already exists (and ensure existing are true). Details: If you want to use androidx-namespaced libraries in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher … Read more