I'm currently using Android Studio 2.0 preview 4. I have followed the guide from tools.android.com and tested NDK samples from github. The samples worked without a hitch, but when I implemented it on the SIPdroid project, it throws this error when I rebuild the project:
Error:(78, 1) A problem occurred configuring project ':app'.
Exception thrown while executing model rule: model.android
Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl
when I try to use gradle project sync it gives this error:
Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Possible causes for this unexpected error include:You are using JDK version 'java version "1.7.0_79"'. Some versions of JDK 1.7 (e.g. 1.7.0_10) may cause class loading errors in Gradle.
Please update to a newer version (e.g. 1.7.0_67).
Open JDK SettingsGradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Android project structure now looks like this. previously the jni folder is separated from the java folder.
Here's my config:
SIPdroid/app/build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.test.sipdroid"
minSdkVersion = 15
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
/*
* native build settings
*/
android.ndk {
moduleName = "SIPdroid"
/*
* Other ndk flags configurable here are
* cppFlags.add("-fno-rtti")
* cppFlags.add("-fno-exceptions")
* ldLibs.addAll(["android", "log"])
* stl = "system"
*/
}
android.sources {
main.java {
source {
srcDir 'src'
}
}
main.jni {
source {
srcDirs = []
}
}
main.jniLibs {
source {
srcDirs = ['src/main/libs']
}
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters.add("armeabi")
}
create("arm7") {
ndk.abiFilters.add("armeabi-v7a")
}
create("arm8") {
ndk.abiFilters.add("arm64-v8a")
}
create("x86") {
ndk.abiFilters.add("x86")
}
create("x86-64") {
ndk.abiFilters.add("x86_64")
}
create("mips") {
ndk.abiFilters.add("mips")
}
create("mips-64") {
ndk.abiFilters.add("mips64")
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
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'
}
SIPdroid/build.gradle
// 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.4.0'
// classpath 'com.android.tools.build:gradle:1.3.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
SIPdroid/gradle-wrapper.properties
#Mon Jan 04 16:06:26 PHT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
SIPdroid/local.properties
ndk.dir=/path/Android/sdk/ndk-bundle
sdk.dir=/path/Android/sdk
I just recently solved my issue by adding this to my orignal app/build.gradle file without using the experimental gradle build ('com.android.tools.build:gradle-experimental:0.4.0') as indicated in the google samples.
This solution finally solved the issue NDKBuild Failure. This additional script builds your jni files using ndkBuild.
app/build.gradle
sourceSets.main {
jniLibs.srcDir 'src/main/libs' // use the jni .so compiled from the manual ndk-build command
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec) {
// commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath <-- Not working
commandLine '/home/user/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
SIPdroid/build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
You also need to have an empty libs folder under app/src/main. My mistake was that I renamed the /jni folder to /libs. After running the build, it will compile your jni to the /libs folder to .so files
jniLibs in your Android project structure view will look like this. This is from your app/src/main/libs as indicated in your build.gradle script
I hope this helps.
Related
I'm trying to load an existing project and i'm running into these problems:
clicking ok i will have this:
Searching here I have not found grangle 2.2.2. Minimum grandle is 3.0.0
build.grandle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
app.build.grande:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.prouast.heartbeat"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
// add a task that calls regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // relative path to jni source
'NDK_LIBS_OUT=../jniLibs',
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task ndkClean(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath, // relative path to jni source
'NDK_LIBS_OUT=../jniLibs',
'clean'
}
// add this task as a dependency of Java compilation
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(['ndkBuild'])
}
clean.dependsOn(['ndkClean'])
sourceSets.main {
jni.srcDirs = []
//jniLibs.srcDir 'src/main/libs'
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':libraries:opencv')
}
Need I to change something on app grandle or anybody have some suggestion?
Could you suggest me some links to follow or explain step by step how can I solve it?
EDIT :
adding the jcenter to gradle.build resolves the issue:
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
Click Ok for gradle wrapper or go manually at build.gradle and update the following line :
**classpath 'com.android.tools.build:gradle:3.2.1'**
Just click OK for Studio to automatically perform the Gradle configuration.
I'm a newbie for developing android program and I'm struggling to get the sample code "ndk-treasurehunt" running. I followed the instructions to build the project and ran into many errors. After modified the build.gradle file, I was able to make a few progress but right now I'm still stuck with the following error.
Build command failed.
Error while executing process C:\Users\xxx\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\xxx\ProgrammingAndroid\gvr-android-sdk-1.150.0\samples\ndk-treasurehunt.externalNativeBuild\cmake\debug\x86 --target treasurehunt_jni}
ninja: error: '../../../../libraries/jni/x86/libgvr.so', needed by '../../../../build/intermediates/cmake/debug/obj/x86/libtreasurehunt_jni.so', missing and no known rule to make it.
The build.gradle I modified is like this:
apply plugin: 'com.android.application'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.google.vr.ndk.samples.controllerpaint"
minSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
cppFlags "-std=gnu++11"
arguments "-DGVR_LIBPATH=${project.rootDir}/libraries/jni",
"-DGVR_INCLUDE=${project.rootDir}/libraries/headers"
}
}
buildTypes {
release {
minifyEnabled = true
proguardFiles.add(file("${project.rootDir}/proguard-gvr.txt"))
}
}
ndk {
// This sample builds all architectures by default. Note that if you
// only want to build for a specific architecture, you need to
// remove the appropriate lines below. You also need to remove the
// .so files from the apk using
// "packagingOptions {exclude('lib/armeabi-v7a/*')}" in the android
// section.
abiFilters "arm64-v8a"
abiFilters "armeabi-v7a"
abiFilters "x86"
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation 'com.google.vr:sdk-audio:1.150.0'
implementation 'com.google.vr:sdk-base:1.150.0'
}
build.dependsOn(':extractNdk')
Please help! Thank you!
Please ensure that your NDK is installed and extracted correctly by performing the following:
Add the NDK to Android Studio via: Tools -> SDK Manager -> SDK Tools -> NDK
Open Android Studio Terminal at the bottom of IDE or through View -> Tool Windows -> Terminal
Run the following command in the terminal gradelw :extractNdk
In the settings.gradle, uncomment the following line include ':sample:ndk-treasurehunt' which has since been replaced by include ':samples:ndk-hellovr' if you are using a newer NDK
I'm new to Android, so forgive me if this seems a little amature. I have two pre-built static libraries, feta (../../feta/build/libfeta.a) and mish (../../mish/build/libmish.a), and I have the shared JNI library. Using the JNI library works perfectly fine, but I'm trying to access both feta and mish via the JNI library. These two libraries are constantly changed and updated along with the Android project so copying them every time they're built isn't really an option (if that'd even fix the linking problem), and I'd much not prefer simply copying the source files into the Android project.
I've tried searching, but most of the answers use the old version of the system and want me to modify Android.mk, which I don't have. I'm using the most recent version of Android Studio, it uses the Gradle plugin.
I've attempted to use all the configuration from over a dozen tutorials and Stackoverflow answers in various setups, but with no luck.
If you answer, please provide a full and working build.gradle so I don't run into the same problems I've been getting from the other answers (thanks!).
I've asked this question after just following this tutorial, so all the files will reflect that.
Here's the build error I'm getting:
Error:A problem occurred configuring project ':app'.
> The following model rules could not be applied due to unbound inputs and/or subjects:
android.sources { ... } # app/build.gradle line 58, column 5
subject:
- android.sources Object [*]
repositories { ... } # app/build.gradle line 39, column 5
subject:
- repositories Object [*]
[*] - indicates that a model item could not be found for the path or type.
Here's my build.gradle file inside the app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.neonorb.mish_android"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++14 -Wno-implicit-exception-spec-mismatch"
}
}
ndk {
// ${targetPlatform.getName()}
// ${buildType.getName()}
stl "c++_static"
abiFilters "x86_64"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
model {
repositories {
libs(PrebuiltLibraries) {
feta {
headers.srcDir "../../feta/include/"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("../../feta/build/libfeta.a")
}
}
}
libs(PrebuiltLibraries) {
mish {
headers.srcDir "../../mish/include/"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("../../mish/build/libmish.a")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "feta" linkage "static"
library "mish" linkage "static"
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.android.support:design:25.1.0'
testCompile 'junit:junit:4.12'
}
And here's the root (mish-android) directory one:
// 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:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here's my CMakeLists.txt:
# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
mish-android
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
src/main/cpp/mish.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
mish-android
# Links the target library to the log library
# included in the NDK.
${log-lib} )
Here's my directory structure if it helps at all.
As it turns out, I needed to upgrade my Gradle plugin. I was able to delete CMakeLists.txt. I also needed to upgrade my Gradle wrapper version to 3.2 to support the new experimental plugin.
Here's my root build.gradle:
// 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:2.2.3'
classpath 'com.android.tools.build:gradle-experimental:0.9.0-beta1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here's my app build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.neonorb.mish_android"
minSdkVersion.apiLevel 15
targetSdkVersion.apiLevel 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
ndk {
moduleName "mish-android"
ldLibs.add("log")
cppFlags.add("-std=c++14")
cppFlags.add("-Wno-implicit-exception-spec-mismatch")
// ${targetPlatform.getName()}
// ${buildType.getName()}
stl "c++_static"
abiFilters.addAll(["x86_64"])
// only build for x86_64 because that's all Feta and Mish support atm
}
buildTypes {
release {
minifyEnabled false
proguardFiles.add(file("proguard-rules.pro"))
}
}
sources {
main {
jni {
source {
srcDir "src"
}
dependencies {
library "feta" linkage "static"
library "mish" linkage "static"
}
}
}
}
}
repositories {
libs(PrebuiltLibraries) {
feta {
headers.srcDir "../../feta/include/"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("../../feta/build/libfeta.a")
}
}
}
libs(PrebuiltLibraries) {
mish {
headers.srcDir "../../mish/include/"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("../../mish/build/libmish.a")
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
I am trying to integrate NDK into my project. I am using Gradle wrapper 2.9 and classpath:gradle-experimental:0.6.0-alpha3.
Project level gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.ms.knowursensor.android"
minSdkVersion.apiLevel = 11
targetSdkVersion.apiLevel = 23
}
}
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
android.ndk {
moduleName = "sensorgraph"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.productFlavors {
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create("x86") {
ndk.abiFilters += "x86"
}
create("x86-64") {
ndk.abiFilters += "x86_64"
}
create("mips") {
ndk.abiFilters += "mips"
}
create("mips-64") {
ndk.abiFilters += "mips64"
}
create("all")
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
}
On building app, i receive this error:
Error:Unable to load class
'com.android.build.gradle.managed.BuildType$Impl'. Possible causes for
this unexpected error include:Gradle's dependency cache may be
corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires
network)The state of a Gradle build process (daemon) may
be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires
restart)Your project may be using a third-party plugin
which is not compatible with the other plugins in the project or the
version of Gradle requested by the project.In the case of
corrupt Gradle processes, you can also try closing the IDE and then
killing all Java processes.
After modifying description of proguard and product flavor i am receiving this error:
Error:A problem occurred configuring project ':app'.
> The following model rules could not be applied due to unbound inputs and/or subjects:
compileOptions.with { ... } # app\build.gradle line 15, column 5
subject:
- compileOptions.with Object [*]
dependencies { ... } # app\build.gradle line 68, column 6
subject:
- dependencies Object [*]
[*] - indicates that a model item could not be found for the path or type.
I had exactly the same problem, and the solution was putting 'dependencies' outside the model {}.
I don't know if this will solve your problem but it may have created complications that led up to it.
Try:
proguardFiles.add(file("proguard-rules.txt"))
ndk.abiFilters.add("armeabi")
Instead of the += operators. Support around the list aggregation methods has been chunky and I've found the .add() method is the one best supported.
Try killing the daemon and rerunning the build
gradle --stop && gradle clean build
I followed this guide to build an ndk hybrid project on Android Studio 1.3.0 RC1 with gradle-experimental:0.1.0.
Everything is OK, but if I try to add test library dependency, I found the method androidTestCompile is not supported any more. Like this:
And testCompile also cause the same error.
The offical guide doesn't talk about this. So, how can I add add test dependency gradle-experimental Or this version do not supports this function?
This is my 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.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
This is build.gradle(moudle):
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 22
buildToolsVersion = "23.0.0 rc3"
defaultConfig.with {
applicationId = "co.yishun.onemoment.app"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
versionCode = 5
versionName = "2.0 canary"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
}
android.buildTypes {
release {
isMinifyEnabled = true
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
create("flavor1") {
applicationId = 'com.app'
}
}
android.ndk {
moduleName = "c_test"
}
}
dependencies {
androidTestCompile 'com.android.support.test:runner:0.3'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.3'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
}
You need to ensure that you are using Gradle 2.5. Under File > Project Structure, navigate to Project and set the "Gradle version" to 2.5. Under File > Settings, navigate to Build, Execution, Deployment > Build Tools > Gradle and make sure that "Use default Gradle wrapper (recommended)" is checked. Also edit the Gradle wrapper by editing your project's gradle/wrapper/gradle-wrapper.properties file. Mine looks like this:
#Mon Jul 13 17:55:42 EDT 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
I did these steps in the above order, but after thinking about it when writing this, perhaps it would be best to reverse the order. I found that I needed to completely exit Android Studio and restart it before all the changes were recognized. Perhaps something was cached somewhere, or perhaps this was an artifact of the order in which I did things.
Also, see this thread for a little more info about setting the Gradle version.