I'm following Create Hello-JNI With Android Studio.
MAC OX 10.11.5
Android Studio 2.2 stable
java version: 1.7.0_79
gradle-2.14.1
Here's my app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.chenql.helloandroidjni"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
ndk {
moduleName "hello-android-jni"
}
}
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:23.3.0'
compile 'com.android.support:design:23.3.0'
testCompile 'junit:junit:4.12'
}
Here's the error:
The Error Message
Error:(20, 0) Could not find method ndk() for arguments [build_13jh6qtzl4f08f8c1of3mvsys$_run_closure1$_closure5#5b127949] on project ':app' of type org.gradle.api.Project.
Open File
It turns out that this code
ndk {
moduleName "hello-android-jni"
}
should be placed under "defaultConfig" block:
defaultConfig {
applicationId "com.chenql.helloandroidjni"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
moduleName "hello-android-jni"
}
}
instaed of after "buildTypes" block.
Upgrading to a newer version of the Gradle plugin solves
You just add the following code in android/app/build.gradle
android {
ndkVersion rootProject.ext.ndkVersion //<-- add line
compileSdkVersion rootProject.ext.compileSdkVersion
And in android/build.gradle
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 30
ndkVersion = "22.1.7171670 || {{use your ndk_version}}" //<-- add line
Thats it. Rebuild the app
Comment or delete ndkVersion 'version number' at build.gradle
Related
I just imported a project, but when i try to enter design view this shows up:
My current gradle version is the latest 26.0.2 by the way. I'm not sure what to do, anyone have an idea?
Here are some Gradle Scripts:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion
defaultConfig {
applicationId "com.example.Ron.myapp"
minSdkVersion 15
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
and
// 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:3.0.1'
// 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
}
I solved the problem myself. I upgraded the compileSdkVersion aswell as the minSdkVersion along with the dependencies. It now looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion
defaultConfig {
applicationId "com.example.Ron.myapp"
minSdkVersion 18
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:design:26.0.2'
compile 'com.android.support:cardview-v7:26.0.2'
}
please update your support lib and compileSdkVersion like below.
compileSdkVersion = 25
buildToolsVersion = "25.0.2"
minSdkVersion = 18
// Library versions
supportLibraryVersion = "25.0.0"
also add ConstraintLauout gradle in gradle file.
compile 'com.android.support.constraint:constraint-layout:1.0.2'
For More details please check : https://stackoverflow.com/a/45115111/1343788
known problem
just add
compile 'com.android.support.constraint:constraint-layout:1.0.2'
in your gradle file,
it will fix it
I installed android studio for the first time but got lots of error!
I searched on the web but could not find anything that solve my problem.
now the problem is shown below :
Look at this image
this is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.vahid.game"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
When I create a new project in Android studio I chose 2.3 for API level but when the project installed in platform 4.0.0 it stopped! It works just in 5.0.0 to up!
here is my gradle moudle code and there is no error!!`apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.milad_admin.counter"
minSdkVersion 9
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.2.1'
}
`
I migrate my android app from eclipse to Android Studio. During this "migration" I decided to split my project in 4 modules: GUI module, engine module, commons module and resources module.
The problem is that I cannot include v4 or v7 libs... It does not recognize the import:"import android.support.v4."
Below are the gradles:
1.Genral 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:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
1.Gradle for GUI module(main module):
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:support-v4:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':audiorecengine')
compile 'com.google.android.gms:play-services:7.0.0'
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "com.audioRec"
minSdkVersion 10
targetSdkVersion 22
versionCode 73
versionName "4.0.4"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
lite {
applicationId = "com.audioRec"
versionCode 73
versionName "4.0.4"
}
pro {
applicationId = "com.audioRec.pro"
versionCode 13
versionName "3.0.3"
}
}
}
Gradle for engine module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 22
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:22.0.0'
compile project(':audioreccommons')
}
It appears that the issue was caused by GooglePlayService lib which already contained the v4 support library. The solution was to exclude support-v4 when compiling playServices.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':audiorecengine')
compile ('com.google.android.gms:play-services:7.0.0'){
exclude module: 'support-v4'
}
}
Also I removed v4 from gradle dependency because it is already contained by the v7 support lib
Test running failed:
Permission Denial: starting instrumentation ComponentInfo{com.xxx.taskmanager.warehouse.tests/android.test.InstrumentationTestRunner} from pid=766, uid=766 not allowed because package com.xxx.taskmanager.warehouse.tests does not have a signature matching the target com.xxx.taskmanager.warehouse
Empty test suite.
This is my app.gradle file
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
android {
signingConfigs {
release
{
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('../keystore.jks')
storePassword 'xxx'
}
}
compileSdkVersion 16
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.0"
testApplicationId "com.xxx.taskmanager.warehouse.tests"
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'LICENSE'
exclude 'NOTICE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
"FLO_HANDHELD_V${variant.versionName}.apk"
)
}
}
variantFilter { variant ->
if(variant.buildType.name.equals('debug')) {
variant.setIgnore(true);
}
}
productFlavors {
production_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2B"
}
stage_b2b {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2B"
}
production_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Prod-B2C"
}
stage_b2c {
applicationId "com.xxx.taskmanager.warehouse"
minSdkVersion 16
targetSdkVersion 16
versionCode 3
versionName "3.1-Stage-B2C"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files ('libs/android-support-v7-appcompat.jar')
compile files('libs/android-support-v4.jar')
compile project(':taskmanagerlib')
compile files('libs/DataCollection.jar')
androidTestCompile fileTree(dir: 'libs', include: 'robotium-solo-5.3.0.jar')
}
task copyTask(type: Copy) {
from 'build/outputs/apk'
into 'apks'
exclude '**/*-unaligned.apk'
}
task deleteApk(type: org.gradle.api.tasks.Delete){
// delete 'apks'
}
task appBuild(dependsOn: ['deleteApk','clean', 'assembleRelease', 'copyTask']){
assembleRelease.mustRunAfter deleteApk
clean.mustRunAfter deleteApk
copyTask.mustRunAfter assembleRelease
}
I think this error is happening because I have not declared the signingConfigs for test package. If so , how do I declare it. ?
Please help!!
I have solved the issue. Answering it so that it can be useful for someone else.
Solution is for Android Studio :
For the tests to run , the build variant should be debug. Build Variants window is present in the left side of the android studio, if not activated then activate it by click on Build variants tab present on the left side of the android studio.
You either have to change your build variant to debug, or add a testBuildType to your android tag inside your build.gradle file. Like this:
android {
...
testBuildType "release"
}
Clean Your Project.
Uninstall app if already install.
Now Run your project.
It's Completely Working for me.
Had the same problem even with Android Studio 3.x years later. Previous answers did not work for me.
Only cure was to explicitly add the permissions to the test app on the phone.
It worked for me when changed Startapp code to use apk file instead of installed App.
i.e. from :
From :
return GetApp().InstalledApp(Settings.AUTPackageName).EnableLocalScreenshots().ConnectToApp();
To:
return GetApp().ApkFile(Settings.AUTPath).EnableLocalScreenshots().ConnectToApp();