Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build NDK module using gradle experimental plugin? [duplicate]

I'm trying to build project with module which uses NDK. But Gradle build gives error.

this is my build.gradle(Main project)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

   //     classpath 'com.android.tools.build:gradle-experimental:0.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

when I try to use this gradle:1.5.0 it gives error ' Error:(17, 0) Plugin with id 'com.android.model.application' not found.'

On the other hand, If I use gradle-experimental:0.1.0 it gives error ' Error:(17, 0) Plugin with id 'com.android.application' not found.'

How can I solve this error? I have several modules in my project. How can I set gradle with satisfying all modules?

EDITED :

build.gradle(Main project)

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:1.5.0'

        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

def isReleaseBuild() {
    return isTag() && !isSnapshot()
}

def isSnapshot() {
    return version.contains("SNAPSHOT")
}

boolean isTravis() {
    return System.getenv('TRAVIS_BUILD_NUMBER') ? true : false
}

boolean isTag() {
    def tag = System.getenv('TRAVIS_TAG')
    return !(tag == null || tag.isEmpty())
}

def buildNumber() {
    return System.getenv('TRAVIS_BUILD_NUMBER') ?: "0"
}

build.gradle(app)

apply plugin: 'com.android.model.application'

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/releases"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/staging"
    }
}

model {

    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "com.ToxicBakery.viewpager.transforms"
            minSdkVersion.apiLevel = 16
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:cardview-v7:22.0.0'
    compile 'info.hoang8f:fbutton:1.0.5'
    compile project(':contextMenu')
    compile project(':library')
    compile project(':library2')
    compile project(':titanic')
    compile files('libs/universal-image-loader-1.9.4.jar')
    compile project(':staggeredview')
    compile project(':min3d')
}

build.gradle(contextmenu)

apply plugin: 'com.android.model.library'
model {
    android {
        compileSdkVersion = 21
        buildToolsVersion = "21.1.2"

        defaultConfig.with {
            minSdkVersion.apiLevel = 11
            targetSdkVersion.apiLevel = 21
        }

    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.nineoldandroids:library:2.4.0'
}

build.gradle(library)

apply plugin: 'com.android.model.library'
apply plugin: 'signing'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 13
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}
dependencies {
    compile 'com.android.support:support-v13:22.1.1'
}

apply from: '../maven_push.gradle'

build.gradle(library2)

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
}

build.gradle(min3d)

apply plugin: 'com.android.model.library'
model {
    android {
        compileSdkVersion = 15
        buildToolsVersion = "21.0.2"
        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        debug {

        }
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.productFlavors {
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

build.gradle(staggerdview)

apply plugin: 'com.android.model.library'

dependencies {
    compile 'com.android.support:support-v4:19.1.+'
}

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
        }

    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

build.gradle(titanic)

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 22
        buildToolsVersion = '22.0.1'

        defaultConfig.with {
            minSdkVersion.apiLevel  = 11
            targetSdkVersion.apiLevel  = 19
            versionCode = 1
            versionName = "1.0"
        }
    }

    android.buildTypes{
        release {
            minifyEnabled = false
            proguardFiles  += file('proguard-rules.txt')
        }
    }
    android.lintOptions {
        checkReleaseBuilds = false
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:20.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}
like image 438
inin Avatar asked Jan 08 '16 04:01

inin


1 Answers

You should use experimental plugin for NDK purpose:

So your build.gradle(Main Project) will look like:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.4.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

and build.gradle(app) will look like:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            applicationId = "com.sample.codecator"
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 19
        }
    }
}

If you are using any library module then its build.gradle will look like:

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            minSdkVersion.apiLevel = 19
            targetSdkVersion.apiLevel = 19
        }
    }
}

You should put following out of android{...} block:

android.buildTypes
android.sources
android.productFlavors

Like:

model {

android {
            compileSdkVersion = 23
            buildToolsVersion = "23.0.2"

            defaultConfig.with {
                minSdkVersion.apiLevel = 19
                targetSdkVersion.apiLevel = 19
            }


   android.buildTypes {
    release {
        minifyEnabled = false
        proguardFiles.add(file("proguard-rules.pro"))
         }
     }
    android.productFlavors {
       //
    }

    android.sources {
        //
    }
}

Do not forget to set ndk.dir=ndk_path in your local.properties file.

UPDATE

Update android.buildTypes code in your all files like this:

android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles.add(file("proguard-rules.pro"))
        }
    }
like image 146
Anand Singh Avatar answered Sep 19 '22 10:09

Anand Singh