Failed to add navigation dependency - android

I am trying to Add Navigation in my project but its showing failed to add Navigation dependency,
when i click on 'ok' in the window to add these now , its showing failed to add dependency and my navigation xml editor is not visible
here are some screen shots
my build.gradle (app) :-
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.choudhary.myshop"
minSdkVersion 21
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
androidExtensions {
experimental = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures{
viewBinding = true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:29.0.4')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'com.google.firebase:firebase-storage-ktx'
def lifecycle_version = "2.5.0-alpha01"
def arch_version = "2.1.0"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
def nav_version = "2.4.0"
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
// Feature module Support
implementation("androidx.navigation:navigation-dynamic-features-fragment:$nav_version")
// Testing Navigation
androidTestImplementation("androidx.navigation:navigation-testing:$nav_version")
// Jetpack Compose Integration
implementation("androidx.navigation:navigation-compose:2.5.0-alpha01")
}
my build.gradle (project ) :-
buildscript {
ext.kotlin_version = "1.4.32"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Seems like Navigation with version 2.3.6 - 2.4.* shows that problem
You can change only
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.0'
to
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

delete all navigation dependency related , and add this :
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'

Add 2.3.4 instead of 2.3.5/2.5.3
It's working...

Related

Gradle failed to update dependencies in Android Studio

I am trying to update dependencies in build.gradle , but they fail to update and a message like this is always shown
Failed to resolve: ***********
Unresolved dependencies
Could not resolve**************
Note:
No proxy is set
Offline Mode is disabled
When I try to update the dependencies , it starts downloading and after some minutes, it shows an error message ..
I tried to change proxy settings to Auto-Detect , but the same problem keeps occurring
Please help
ext {
var = '54642664'
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
buildscript {
repositories {
google()
mavenCentral()
}
}
allprojects {
repositories {
google()
mavenCentral()
maven{ url 'https://jitpack.io'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
repositories {
mavenCentral()
}
android {
compileSdkVersion 32
buildToolsVersion "30.0.3"
bundle{
language{
enableSplit = false
}
}
defaultConfig {
applicationId "com.afeefinc.electricityinverter"
minSdkVersion 19
targetSdkVersion 32
versionCode 101
versionName "3.9.20"
multiDexEnabled true
resConfigs 'en', 'ar', 'es', 'tr', 'hi', 'ru', 'fr', 'fil', 'zh', 'fa', 'bn', 'de', 'in', 'ur', 'af', 'pt', 'it', 'my', 'uk', 'ro', 'el', 'vi', 'th', 'ja', 'iw', 'ku', 'ko', 'nl'
//Define languages that your app supports.
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.afeefinc.electricityinverter'
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.5.0'
implementation 'androidx.navigation:navigation-ui:2.5.0'
implementation 'org.jetbrains:annotations:22.0.0'
implementation 'com.google.android.gms:play-services-location:20.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.philJay:MPandroidChart:v3.1.0'
implementation 'com.google.firebase:firebase-inappmessaging-display'
implementation platform('com.google.firebase:firebase-bom:30.0.0')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-auth'
implementation 'androidx.annotation:annotation:1.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation("com.android.billingclient:billing:5.0.0")
implementation 'com.google.firebase:firebase-dynamic-module-support:16.0.0-beta02'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime:2.5.0"
annotationProcessor "androidx.lifecycle:lifecycle-common-java8:2.5.0"
implementation 'com.anjlab.android.iab.v3:library:2.0.0'
implementation 'androidx.work:work-runtime-ktx:2.8.0-alpha02'
implementation 'com.github.bumptech.glide:glide:4.13.0'
implementation 'com.google.firebase:firebase-analytics'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'
implementation 'com.github.jd-alexander:LikeButton:0.2.3'
// annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.4.1"
implementation "android.arch.lifecycle:common-java8:1.1.1"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

Could not find android.arch.navigation:navigation-safe-args-gradle-plugin:2.3.5.?

I am using android navigation components but it is giving an error A problem occurred configuring root project 'AndroidCodingChallenge'.
Could not resolve all artifacts for configuration ':classpath'.
Could not find android.arch.navigation:navigation-safe-args-gradle-plugin:2.3.5.
Searched in the following locations:
below my app.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'kotlin-kapt'
apply from: '../commons.gradle'
android {
compileSdkVersion 30
buildFeatures {
dataBinding = true
// for view binding:
// viewBinding = true
}
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.androidcodingchallenge"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables{
useSupportLibrary = true
}
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
dependencies {
implementation project(':data')
implementation project(':domain')
implementation project(':presentation')
implementation project(':remote')
implementation project(':cache')
implementation project(':common')
implementation project(':device')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "com.google.android.material:material:$material_version"
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//navigation component
// implementation "androidx.navigation:navigation-fragment-ktx:2.3.2"
// implementation "androidx.navigation:navigation-ui-ktx:2.3.2"
// UI
implementation "com.github.bumptech.glide:glide:$glide_version"
kapt "com.github.bumptech.glide:compiler:$glide_version"
// Ktx
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0'
implementation "androidx.fragment:fragment-ktx:1.3.0"
// Navigation
implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"
//viewpager2
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'
//indicator
implementation 'me.relex:circleindicator:2.1.4'
//lottie
implementation "com.airbnb.android:lottie:3.4.1"
//datastore
implementation "androidx.datastore:datastore-preferences:1.0.0-alpha06"
implementation 'androidx.hilt:hilt-navigation-fragment:1.0.0-alpha03'
//LeakCanary
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakcanary_version"
//Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
//multidex
implementation 'com.android.support:multidex:1.0.3'
}
below my commons.gradle
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
androidExtensions {
experimental = true
}
android {
// compileSdkVersion Versions.compileSdkVersion
// buildToolsVersion Versions.buildTool
// defaultConfig {
// minSdkVersion Versions.minSdk
// targetSdkVersion Versions.targetSdk
// versionCode Releases.versionCode
// versionName Releases.versionName
// vectorDrawables.useSupportLibrary = true
// }
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
kapt {
javacOptions {
// Increase the max count of errors from annotation processors.
// Default is 100.
option("-Xmaxerrs", 500)
}
// Configure kapt to correct error types for Hilt
correctErrorTypes true
}
buildFeatures{
dataBinding = true
}
kotlinOptions {
jvmTarget = "1.8"
}
lintOptions {
abortOnError false
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
//Loads packaged libraries in the libs folder
implementation fileTree(dir: 'libs', include: ['*.jar'])
// implementation KotlinLibraries.kotlin
// implementation AndroidLibraries.coreKtx
//
// implementation Libraries.hilt
// implementation Libraries.hiltJetpack
// kapt Libraries.hiltCompiler
// kapt Libraries.hiltJetpackCompiler
//
// // For instrumentation tests
// androidTestImplementation Libraries.hiltAndroidTest
// kaptAndroidTest Libraries.hiltAndroidTestCompiler
//
// // For local unit tests
// testImplementation Libraries.hiltAndroidUnitTest
// kaptTest Libraries.hiltAndroidUnitTestCompiler
//
// implementation TestLibraries.androidTestRunner
// implementation TestLibraries.junit
// implementation TestLibraries.espresso
// implementation TestLibraries.espressoContrib
// Concurrency
implementation "io.reactivex.rxjava2:rxkotlin:$rxkotlin_version"
implementation "io.reactivex.rxjava2:rxandroid:$rxandroid_version"
//Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_androidx_version"
kapt "androidx.hilt:hilt-compiler:$hilt_androidx_version"
// Utils
implementation "com.jakewharton.threetenabp:threetenabp:$threetenabp_version"
}
below build.gradle where I have declare buildpaths
buildscript {
ext{
kotlin_version = "1.4.20"
version_navigation = "2.3.5"
hilt_version = '2.31.2-alpha'
version_navigation = "2.3.5"
version_lifecycle_extensions = "2.2.0"
lifecycle_version = "2.2.0"
hilt_androidx_version = "1.0.0-alpha03"
material_version = "1.3.0"
coroutines_version = "1.4.1"
junit_version = "4.13"
retrofit_version = "2.9.0"
okHttp_version = "4.9.0"
moshi_converter_version = '2.9.0'
moshi_version = '1.11.0'
mockwebserver_version = "4.9.0"
robolectric_version = "4.4"
mockito_version = "3.5.15"
google_truth_version = "1.0"
coroutines_test = "1.3.1"
room_version = "2.3.0"
threetenabp_version = "1.2.4"
leakcanary_version = "2.4"
timber_version = "4.7.1"
glide_version = "4.11.0"
androidsvg_version = "1.4"
rxkotlin_version = "2.4.0"
rxandroid_version = "2.1.1"
google_services_version = "4.3.8"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:$google_services_version"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
what I have tried following answers Could not find androidx.navigation:safe-args-gradle-plugin:1.0.0-alpha01 and it did not help I want to know what I am missing
You're using android.arch.navigation, which is not the AndroidX version of Navigation. You need to replace each with androidx.navigation as per the Declaring dependencies documentation
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
And similarly with your dependencies:
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation"
implementation "androidx.navigation:navigation-ui-ktx:$version_navigation"

Autocomplete or Code Analyzer not working in Android Studio

I am currently working on recyclerview adapter. I can not work further because my autocomplete/code analyzer is apparently not working. I need it to generate the implementation of Recyclerview.Adapter automatically. please help me..
I have a hunch that the problem was caused by my gradle configuration. FYI, everything works fine before i resync my gradle (module). here is my current gradle configuration:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.toharifqi.myfavoritesports"
minSdkVersion 21
targetSdkVersion 30
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
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.constraintlayout:constraintlayout:$constraint_version"
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "com.github.bumptech.glide:glide:$glide_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
kapt "androidx.room:room-compiler:$room_version"
androidTestImplementation "androidx.room:room-testing:$room_version"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:logging-interceptor:$logging_interceptor_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "org.koin:koin-core:$koin_version"
implementation "org.koin:koin-android:$koin_version"
implementation "org.koin:koin-android-viewmodel:$koin_version"
}
and this is my gradle configuration for project level:
buildscript {
ext.kotlin_version = "1.4.10"
ext.appcompat_version = "1.1.0"
ext.core_ktx_version = "1.3.2"
ext.constraint_version = "2.0.4"
ext.legacy_support_version = "1.0.0"
ext.junit_version = "4.13.1"
ext.androidx_junit_version = "1.1.2"
ext.espresso_version = "3.3.0"
ext.multidex_version = "2.0.1"
ext.cardview_version = "1.0.0"
ext.recyclerview_version = "1.1.0"
ext.material_version = "1.2.1"
ext.glide_version = "4.12.0"
ext.room_version = "2.2.5"
ext.retrofit_version = "2.9.0"
ext.logging_interceptor_version = '4.9.0'
ext.kotlin_coroutines_version = "1.3.9"
ext.lifecycle_version = "2.2.0"
ext.koin_version = "2.1.6"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have just found the problem, it was caused by my android core ktx version. previously it was implementation 'androidx.core:core-ktx:1.5.0'. After I changed to implementation 'androidx.core:core-ktx:1.3.2' everything works fine. thank you

Android Studio Arctic Fox | 2020.3.1 Canary 15 |Compose Build error: Could not find androidx.compose:compose-compiler:1.0.0-beta06 |

as the title suggests I can't understand what the problem is when I try to deploy on the device.
The deployment fails when I try to add kotlinCompilerExtensionVersion '1.0.0-beta06' to the gradle
and the error message is "Could not resolve all files for configuration ': app: kotlin-extension'. Could not find androidx.compose: compose-compiler: 1.0.0-beta06."
What I'm trying to do is add a piece of code written in compose starting from an existing project, and I'm following this guide https://developer.android.com/jetpack/compose/interop/interop-apis
I paste my gradle below:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs'
}
android {
compileSdkVersion rootProject.findProperty("android.compileSdkVersion") as Integer
buildToolsVersion "29.0.3"
defaultConfig {
applicationId findProperty("android.applicationId")
targetSdkVersion findProperty("android.targetSdkVersion") as Integer
minSdkVersion findProperty("android.minSdkVersion") as Integer
versionCode findProperty("android.minSdkVersion") as Integer
versionName findProperty("android.versionName")
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
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
buildFeatures {
dataBinding true
// Enables Jetpack Compose for this module
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.0.0-beta06'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "androidx.legacy:legacy-support-v4:$legacy_version"
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
implementation "com.google.android.material:material:$material_version"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
// Compose
implementation "androidx.navigation:navigation-compose:$navigation_compose_version"
// Material Design
implementation "androidx.compose.material:material:$compose_version"
// Tooling support (Previews, etc.)
implementation "androidx.compose.ui:ui-tooling:$compose_version"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation "androidx.compose.foundation:foundation:$compose_version"
// Material design icons
implementation "androidx.compose.material:material-icons-core:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
// Integration with activitie
implementation "androidx.activity:activity-compose:1.3.0-alpha07"
// Integration with ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha04"
// Integration with observable
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.runtime:runtime-rxjava2:$compose_version"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
// Room
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
// Work Manager
implementation "androidx.work:work-runtime-ktx:$work_version"
// Timber
implementation "com.jakewharton.timber:timber:$timber_version"
// Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I'm using last version at moment I'm writing:
android.targetSdkVersion=30
android.minSdkVersion=28
android.versionCode=1
android.versionName=1.0.0
# gradle.properties
kotlin_version=1.4.30
gradle_version=4.1.1
ktlint_version=9.2.1
safe_args_version=1.0.0
appcompat_version=1.2.0
ktx_version=1.3.2
legacy_version=1.0.0
constraint_layout_version=2.0.4
lifecycle_version=2.3.1
recyclerview_version=1.2.0
material_version=1.3.0
retrofit_version=2.9.0
moshi_version=1.9.2
navigation_version=2.3.5
navigation_compose_version=1.0.0-alpha10
compose_version=1.0.0-beta06
coroutine_version=1.4.2
room_version=2.3.0
work_version=2.5.0
timber_version=4.7.1
glide_version=4.12.0
I'm following the official setup but not seem woking
https://developer.android.com/jetpack/compose/setup
I had this issue yesterday. What I did was adding compiler in the compose option.
composeOptions {
kotlinCompilerVersion "1.4.32"
kotlinCompilerExtensionVersion "1.0.0-beta06"
}
Found somewhat similar issue to yours in stackoverflow here. You may need to upgrade your gradle version.
Also here, (if you haven't already) set ext.kotlin_version = ..... in the project gradle
buildscript {
ext.kotlin_version = "1.4.32"
ext { .... }
repositories {
mavenCentral()
google()
}
allprojects {
repositories {
mavenCentral()
google()
maven { url "https://jitpack.io" }
}
}
}
Finally found the problem.
Inside build.gradle (project level) I was using:
classpath "com.android.tools.build:gradle:$gradle_version"
So creating new Compose project I found how to fix the problem. In particular:
build.gradle (project level) is like:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0-alpha15"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32"
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_version"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5")
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (app level) is like:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs'
}
android {
compileSdkVersion rootProject.findProperty("android.compileSdkVersion") as Integer
buildToolsVersion "29.0.3"
defaultConfig {
applicationId findProperty("android.applicationId")
targetSdkVersion findProperty("android.targetSdkVersion") as Integer
minSdkVersion findProperty("android.minSdkVersion") as Integer
versionCode findProperty("android.minSdkVersion") as Integer
versionName findProperty("android.versionName")
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
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
dataBinding true
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "androidx.legacy:legacy-support-v4:$legacy_version"
implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.recyclerview:recyclerview:$recyclerview_version"
implementation "com.google.android.material:material:$material_version"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
implementation "com.squareup.moshi:moshi-kotlin:$moshi_version"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$navigation_version"
// Compose
implementation "androidx.navigation:navigation-compose:$navigation_compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
// Kotlin
implementation "androidx.fragment:fragment-ktx:$fragment_version"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
// Room
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
// Work Manager
implementation "androidx.work:work-runtime-ktx:$work_version"
// Timber
implementation "com.jakewharton.timber:timber:$timber_version"
// Glide
implementation "com.github.bumptech.glide:glide:$glide_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
and Upgrade JDK to 11 using embedded JDK
and at last upgrade gradle to 7.0.0
P.S.
here gradle.properties:
# Common Android settings
android.compileSdkVersion=30
android.applicationId=com.composetest.application
android.targetSdkVersion=30
android.minSdkVersion=28
android.versionCode=1
android.versionName=1.0.0
# gradle.properties
kotlin_version=1.4.32
gradle_version=4.1.1
ktlint_version=9.2.1
safe_args_version=1.0.0
appcompat_version=1.3.0-beta01
ktx_version=1.3.2
legacy_version=1.0.0
constraint_layout_version=2.0.4
lifecycle_version=2.3.1
recyclerview_version=1.2.0
material_version=1.3.0
retrofit_version=2.9.0
moshi_version=1.9.2
navigation_version=2.3.5
navigation_compose_version=1.0.0-alpha10
compose_version=1.0.0-beta06
coroutine_version=1.4.2
room_version=2.3.0
work_version=2.5.0
timber_version=4.7.1
glide_version=4.12.0
fragment_version = 1.3.3

Unresolved refrence: requireLensFacing | Android Studio

I am getting 'Unresolved reference: requireLensFacing' for CameraSelector.Builder.requireLensFacing(lensFacing).build()
I have added camera core dependencies and I can actually open up the CameraSelector class and find the 'requireLensFacing' method inside it. But I just can't use it.
Here is my app gradle:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.devtyagi.facemaskdetector"
minSdkVersion 21
targetSdkVersion 30
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
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures{
mlModelBinding true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
implementation 'com.google.android.material:material:1.2.1'
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha20"
implementation "androidx.camera:camera-extensions:1.0.0-alpha20"
implementation "org.tensorflow:tensorflow-lite-metadata:${tflite}"
implementation "org.tensorflow:tensorflow-lite-gpu:2.2.0"
implementation 'org.tensorflow:tensorflow-lite-support:0.1.0-rc1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
And here is my Project Level gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.21"
ext.tflite = "0.1.0-rc1"
ext.camerax_version = "1.0.0-rc01"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is the error:
Screenshot
How do I resolve this issue?
Thank You
You should use it like this val cameraSelector = CameraSelector.Builder().requireLensFacing(lensFacing).build()
you are using Builder replace it with Builder()

Categories

Resources