Could not find method namespace() for arguments [com.android.mylib] on extension 'android' of type com.android.build.gradle.LibraryExtension - android-studio

I am trying to create a library in android studio by following this official documentation. But in this particular project, I am facing this issue. if I create new project and create new lib I don't face any issue.
My Lib Gradle
plugins {
id 'com.android.library'
}
android {
namespace 'com.android.mylib'
compileSdkVersion 33
defaultConfig {
minSdkVersion 26
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
App Gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 33
buildToolsVersion "30.0.2"
testBuildType "beta"
defaultConfig {
applicationId "com.app.etc"
minSdkVersion 23
targetSdkVersion 33
versionCode 327
I have searched some questions, but according to those answers, everything seems correct. i have invalidated cache and restarted the android studio as well.

Related

android libraries errors

i am working on an android studio project, when i run the project it crashes immedietly, i tried to debug and i found that the problem is in the methods i use from the android libraries as in the pic here
(https://i.stack.imgur.com/a6bKI.png)
i updated the android SDK
repaired the IDE
added the depencencies needed to the build.gradle file but the problem is not solved
bellow is the build.gradle
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.readerapp'
compileSdk 33
defaultConfig {
applicationId "com.example.readerapp"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation "androidx.annotation:annotation:1.5.0"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation "androidx.constraintlayout:constraintlayout-compose:1.0.1"
implementation 'com.google.android.material:material:1.5.0'
implementation files('libs\\uhfcom13_eu_v15.jar')
implementation files('libs\\SerialPort.jar')
}
Go To: File->Invalidate Caches-> Rebuild Project
I faced the same issue and that fixed my problem.
implementation files('libs\\uhfcom13_eu_v15.jar')
implementation files('libs\\SerialPort.jar')
Replace with:
implementation files('libs\uhfcom13_eu_v15.jar')
implementation files('libs\SerialPort.jar')

Koltin Code is not syntax-highlighted : Only happens in .kt file

Week ago, it used to be working fine. I think it's cause by I changed the gradle path in system like this link. It only happens on .kt, others like build.gradle are fairly highlighted.
Build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.codemobiles.project_eva"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/io.netty.versions.properties'
}
compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
}
}
Solution : I completely wipe out the android studio to fix this problem

android studio : minSdkVersion 22 error

I am a complete beginner in android studio and I was having trouble with setting minSdkVersion to 22 for android wear. The problem is caused because of library dependency since it requires the minSdkVersion to be 23 minimum. I looked up in the web and didn't seem to find a solution of how to set the minSdkVersion to 22.
The cod is given below
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "enterprise.supti.myapplication"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.android.support:wearable:2.3.0'
implementation 'com.google.android.gms:play-services-wearable:15.0.1'
implementation 'com.android.support:percent:28.0.0-rc01'
implementation 'com.android.support:support-v4:28.0.0-rc01'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
implementation 'com.android.support:wear:28.0.0-rc01'
compileOnly 'com.google.android.wearable:wearable:2.3.0'
implementation 'com.android.support:support-annotations:28.0.0-rc01'
}

How can I solve Android studio API platform

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'
}
`

Could not find method ndk() for arguments

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

Resources