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

1

6

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'])
}
Swedenborgian answered 8/1, 2016 at 4:46 Comment(0)
R
5

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"))
        }
    }
Rohn answered 8/1, 2016 at 5:2 Comment(13)
do I have to change all module's gradle like module{...}?Swedenborgian
I think yes, because you are using com.android.tools.build:gradle-experimental:0.4.0 gradle plugin and it will support 'com.android.model.application' only.Rohn
I'm changing all modules to 'com.android.model.library' instead of 'com.android.library'. but suddenly it gives the other error -"Error:Could not find property 'android' on task ':library:androidJavadocs'." can you help me what this error means?Swedenborgian
@shj you also have to use model instead of android like I did in build.gradle(app) code above. In that pattern you have to modify it.Rohn
I changed my all gradle to use model as you mentioned above. But it gives the other error. Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'. How to solve this error?Swedenborgian
can you please share your code here?Rohn
@shj check my edited answer.Rohn
I tried your answer. another error 'com.android.build.gradle.managed.BuildType_Impl' I added my module's gradle files. can you please check it?Swedenborgian
@shj android.buildTypes it should be outside of android but inside of model Please check my answer I gave one example code too at last of post. You should edit like that.Rohn
I think I followed your answer. android.buildTypes is outside of android and inside of model in all my gradle code. can you check again, please?Swedenborgian
@shj check the updated answer.Rohn
@shj do not forget to accept answer if your problem is solved :)Rohn
Thanks! It works perfectly now! It seems to replace all '+=' equations to 'add()' in gradle files.Swedenborgian

© 2022 - 2024 — McMap. All rights reserved.