I'm new in NDK .and try to setup Integration with NDk .But after research through many sites ,i could not solved my problem. Here is build.gradle file
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
}
android.ndk {
moduleName "native"
}
defaultConfig.with {
applicationId "app.com.jnitester"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 23
versionCode 1
versionName "1.0"
buildConfigFields {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
/* android.ndk {
moduleName = "native"
}*/
android.buildTypes {
release {
minifyEnabled false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create("flavor1") {
applicationId "com.app"
}
}
android.sources {
main {
jni {
source {
srcDir 'src'
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
my classpath is:
classpath 'com.android.tools.build:gradle-experimental:0.4.0'
we get error like that:
Error:(18, 0) No signature of method: org.gradle.model.dsl.internal.NonTransformedModelDslBacking.applicationId() is applicable for argument types: (java.lang.String) values: [app.com.jnitester]
Open File
when i put buildTypes,productFlavours,sources inside android{} then it gives Errors like that:
Error:(4, 1) A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> Could not find method compileSdkVersion() for arguments [23] on project ':app'.
may be this question be duplicate but we couldn't find the solution yet .
Your help would save my time. Any Help would be appreciated in Advanced.
try adding '=' char. e.g.
compileSdkVersion 23
change to
compileSdkVersion = 23
Related
I'm currently using Android experimental gradle plugin. I need to have multiple custom sub folder in res but when I combine with main java source srcDirs, it will always prompt error message
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe''
finished with non-zero exit value 1
my gradle version is 2.5
What is the proper way to configure android.sources for experimental gradle version
in my app's build.gradle file:
apply plugin: 'com.android.model.application'
...
android.sources {
main {
java {
source {
srcDirs = ["src"]
}
}
res{
source {
srcDirs = [ 'src/main/res/property/search',
'src/main/res/property',
'src/main/res/agent',
'src/main/res'
]
}
}
}
}
Current latest and standard configuration which i uses for build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.xyz"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.mikhaellopez:circularimageview:2.0.2'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile files('libs/picasso-2.0.0.jar')
compile 'com.github.rahatarmanahmed:circularprogressview:2.4.0'
}
I think you need to add model tag before android, like it
apply plugin: 'com.android.model.application'
...
model.android.sources {
main {
java {
source {
srcDir = 'src'
}
}
res {
source {
srcDirs = ['src/main/res/property/search',
'src/main/res/property',
'src/main/res/agent',
'src/main/res'
]
}
}
}
}
I'm compiling an Android library (.aar) as a module that contains some native code and requires some libraries. Here's the build.gradle:
apply plugin: 'com.android.model.library'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "org.anima.mrubybridge"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.ndk {
moduleName = "mrubybridge"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
CFlags += "-I/home/dragos/Downloads/mruby-1.1.0/include"
ldLibs += ["mruby"]
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create ("arm7") {
ndk.abiFilters += "armeabi-v7a"
ndk.ldFlags += "-L/home/dragos/Downloads/mruby-1.1.0/build/armeabi-v7a/lib"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
This compiles everything (I checked the .class and .so files), but the .aar archives are almost empty with no classes or dynamic libraries. (about 2.3KB)
In the second module, I add this as a dependency:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
//
// NOTE: change the application ID to match the play console linked application.
//
applicationId = "com.example.dragos.mrubytest"
minSdkVersion.apiLevel = 18
targetSdkVersion.apiLevel = 18
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
}
dependencies {
compile project(':mrubybridge')
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
But when I try to add the Java classes from the other module, I get: Error:(12, 29) error: package org.anima.mrubybridge does not exist, most probably because they're not in the .aar.
I've added the module as a dependency (compile project(':mrubybridge')), but it doesn't really help.
I encountered the same issue. This answer solved it for me:
#Radix
"Put the .aar file in the app libs directory (create it if needed), then, add the following code in your app build.gradle":
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
repositories{
flatDir{
dirs 'libs'
}
}
Adding local .aar files to Gradle build using "flatDirs" is not working
I have experience with Android development on Eclipse, but I'm quite new to this gradle stuff.
I created a project on Android Studio and tried adding native library support. I followed the documents on android.com
Android NDK Preview
Experimental Plugin User Guide
I bumped into the following problem and I'm not even familiar with the terminology! It says: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'
Suggestions did not solve the problem. How can I solve it?
Here are the contents of the build.gradle and app/build.gradle:
build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
}
}
allprojects {
repositories {
jcenter()
}
}
app/build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.example.wofm"
minSdkVersion = 15
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
}
android.ndk {
moduleName = "wofmUtil"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles = getDefaultProguardFile('proguard-android.txt')
proguardFiles += 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
}
You should use minSdkVersion.apiLevel and targetSdkVersion.apiLevel instead of minSdkVersion and targetSdkVersion. And I also had a problem with getDefaultProguardFile() so I had to remove it.
I have been trying to configure Android Studio for NDk by following this article and this article. The following are the contents of my gradle-wrapper.properties
#Sat Aug 08 09:36:53 IST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
Following is the contents of build.gradle(project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and finally the build.gradle(module)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"
defaultConfig.with {
applicationId = "com.opaxlabs.nativetest"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
}
android.ndk{
moduleName = "native"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
when I try to sync gradle files I get the following error:
Error:No such property: android for class: com.android.build.gradle.managed.AndroidConfig
the following paths are defined in local.properties
ndk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk/ndk-bundle
sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk
so it looks like I have missed something only I can't locate it.
Any help will be greatly appreciated.
In your build.gradle(module), the android.buildTypes block needs to outside of the android block. So it should look like this:
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"
defaultConfig.with {
applicationId = "com.opaxlabs.nativetest"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.ndk{
moduleName = "native"
}
}
Have you declare your NDK path in Local.property file ??
Looks like the environment path and the local.properties files are pointing to different locations:
PATH: C:\Program Files (x86)\Android\android-ndk-r9d
local.properties: C:\Program Files (x86)\Android\android-studio\android-ndk-r9d
Make sure which is right. You can keep the PATH and drop the local.properties declerations, and then try this command through the console: ndk-build -? to see if it was found in PATH
NDK Build option
ndk {
moduleName "SeePlusPlus" // Name of C++ module (i.e. libSeePlusPlus)
cFlags "-std=c++11 -fexceptions" // Add provisions to allow C++11 functionality
stl "gnustl_shared" // Which STL library to use: gnustl or stlport
}
Could not find property jni and source set 'main'
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.example.native_activity"
minSdkVersion.apiLevel = 9
targetSdkVersion.apiLevel = 9
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir = 'src/main/libs'
// This is not necessary unless you have precompiled libraries in your project.
}
}
Here is the stacktrace:
Caused by: org.gradle.model.internal.core.ModelRuleExecutionException: Exception thrown while executing model rule: model.android
at org.gradle.model.internal.registry.DefaultModelRegistry.fireMutation(DefaultModelRegistry.java:485)
at org.gradle.model.internal.registry.DefaultModelRegistry.access$1500(DefaultModelRegistry.java:45)
at org.gradle.model.internal.registry.DefaultModelRegistry$RunModelAction.apply(DefaultModelRegistry.java:1464)
at org.gradle.model.internal.registry.DefaultModelRegistry.transitionTo(DefaultModelRegistry.java:341)
at org.gradle.model.internal.registry.DefaultModelRegistry.transition(DefaultModelRegistry.java:419)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrMaybeLater(DefaultModelRegistry.java:183)
at org.gradle.model.internal.registry.DefaultModelRegistry.atStateOrLater(DefaultModelRegistry.java:175)
at org.gradle.execution.TaskNameResolver.selfClose(TaskNameResolver.java:101)
at org.gradle.execution.TaskNameResolver.selfClosedTasksNode(TaskNameResolver.java:114)
... 60 more
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method main() for arguments [build_f1cmjkxjjzysskbrs6852ixyj$_run_closure1_closure2_closure7#8c09fa7] on SourceSet container.
I googled like mad for the last 2 hours...
As Awanish said - read the Experimental Plugin User Guide step by step VERY carefully. For even more clearance check the build.gradle files in the ndk-samples provided by google.
sourceSets.main { } has different syntax and should be outside the android { } block. In your case it should look something like this:
model {
android {
//...
}
android.sources {
main {
jniLibs {
source {
srcDirs 'libs'
}
}
}
}
}
In my case it was an exact opposite to tochkov answer:
This syntax - with the jniLibs outside android block - gave me an error:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
and this syntax - inside android block - fixed it:
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.mycompany.myproject"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
}
It seems like you are trying to use the grade experimental plugin!
Make sure you have grade-2.5 in your gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
and this in your project's build.gradle dependencies tag
classpath 'com.android.tools.build:gradle-experimental:0.1.0'
Instead of guessing a lot of things, let me redirect you to the user guide, where the documentation explains migration from the standard to experimental plugin in detail. Take a look here!
Try these fixes. Post more details if these don't work for you, I will try to help. :)
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jeremy.test"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles.add(file('proguard-android.txt'))
}
}
ndk {
moduleName "hello-android-jni"
}
}
android.sources.main {
java.source.srcDirs = ["src/main/java", "/Users/jeremy/Repositories/hello/src/android/java"]
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
The above is copied from my experimental ndk project, this works for me.
See the android.sources.main section.