16

I am trying to import 'https://code.google.com/p/android-serialport-api/'into Android Studio. Since this project involves ndk, I followed the instructions to build NDK from the following link: http://tools.android.com/tech-docs/new-build-system/gradle-experimental

But after building, I get this error: Gradle Project refresh Failed
Error:Cause: org.gradle.api.internal.ExtensibleDynamicObject

EDIT: I have 2.5 gradle version installed Here's my build.gradle

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

model {

  android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig.with {
    applicationId = "android_serialport_api.sample"
    minSdkVersion.apiLevel =  17
    targetSdkVersion.apiLevel = 22

    android.ndk {
        moduleName = "serial_port"
    }

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

    android.productFlavors {

        create("all")
    }

}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
     }
   }

  }

}
Susheel
  • 784
  • 1
  • 12
  • 20
  • 1
    Since that code has not been updated in about four years, I will be surprised if it works. And, personally, I am not touching the `gradle-experimental` stuff until it becomes non-experimental. There is NDK support already in Gradle (it's covered in a book that I know you have). But, most of all, nobody is really going to be able to help you with this without your `build.gradle`, a depiction of how the files are presently organized (e.g., where the JNI source lives), and the rest of the Gradle Console error report (as I would hope that there's more than just that one line). – CommonsWare Aug 10 '15 at 15:37
  • Have you seen http://stackoverflow.com/questions/16667903/android-studio-gradle-and-ndk? And do you have Android NDK r10e and SDK with Build Tools at least version 19.0.0? – serv-inc Aug 10 '15 at 15:42
  • @CommonsWare The code is working in ADT. I am looking at the book chapter now. Also, that is the complete console output. Gradle Project refresh Failed Error:Cause: org.gradle.api.internal.ExtensibleDynamicObject – Susheel Aug 10 '15 at 15:54
  • 2
    other users, like @CommonsWare, will only get notified if you put an `@` in front of the user name (this comment should alert him) – serv-inc Aug 10 '15 at 15:57
  • If that's all that you are getting for an error, I have no idea what may be going on. – CommonsWare Aug 10 '15 at 15:59
  • @user-------: Thanks, I know I went through the link before, but I'm going through it again. – Susheel Aug 10 '15 at 16:04
  • @CommonsWare: Thanks for looking into it – Susheel Aug 10 '15 at 16:04

3 Answers3

30

Can you try change

compileSdkVersion 22
buildToolsVersion "22.0.1"

to

compileSdkVersion = 22
buildToolsVersion = "22.0.1"

and

release {
    minifyEnabled false
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}

to

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

I've got the same error and this works for me.

user2535400
  • 343
  • 1
  • 4
  • 6
  • Your before and after version for the compile tools are the same. My proguard commands look like yours. So I have no idea what's going on – Susheel Aug 18 '15 at 14:02
  • 2
    The "before" is missing the =. Thanks user, this solved the problem for me. – RickBoyerDev Feb 16 '16 at 18:01
  • 2
    In my case using: minSdkVersion.apiLevel 22 targetSdkVersion.apiLevel 22 worked instead of the normal way of doing it. – mtbomb May 29 '16 at 00:27
  • @mtbomb, works for me too. For future readers - read and follow this very carefully: https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#2 – WindRider Jun 29 '16 at 08:50
1

Unfortunately the NDK preview implementation to support native code development in Android Studio is a moving target. Even if you use an older, developers.android.com stated, "supported" combination of the experimental Android Gradle plugin (from tools.android.com) and Gradle version (from gradle.org), good luck in getting the build to work. Instead, always use the latest released combination with the latest indicated module build.gradle language syntax, according to developers.android.com.

In your case, your mixing the use of assignment operators, "=" and "+=". Depending on the supported combo of gradle plugin and gradle version you're using, it's either use the assignment operators everywhere in module build.gradle file or nowhere - you have to be consistent, all or nothing. For "+=" use the method ".add(...)" instead.

And remember, the gradle scripting language is compiled to the Java runtime so when you see a build error that looks like a Java error, it's the gradle scripting that is likely the problem.

BoiseBaked
  • 792
  • 7
  • 15
0

I got this error when I had a parameter not correctly moved from old gradle syntax to new one

(had cFlags "..." rather than CFlags += "...")

Have a look e.g. at http://tools.android.com/tech-docs/new-build-system/gradle-experimental

  • I have the problem and I don't have cFlags to change, so this can't be a general solution. – Mitch Jun 05 '16 at 01:59