How to downgrade Api Level (32 -> 28) Android? - android

I've benn programming my school proyect for several months and now im done. I used to compile my app directly to my phone (Android 12) but I need it to be at least API 28. I tried to change the Build Gradle target version from 31 to 28 but I'm having errors with the dependencies versions.
There is any safe and quick way to know which version exactly I need for each dependency?
Im currently using theese.
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
//Hilt
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.kdapp.estudiapp"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary 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 {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
implementation 'com.google.firebase:firebase-auth-ktx:21.0.6'
implementation 'com.google.firebase:firebase-firestore-ktx:24.2.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
//Firebase
implementation platform('com.google.firebase:firebase-bom:30.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth:21.0.6'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
//Firebase -> Storage
implementation 'com.google.firebase:firebase-storage'
//Navigation
implementation 'androidx.navigation:navigation-compose:2.5.0'
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.3.5"
// Hilt DI
def hilt_lifecycle_viewmodel = "1.0.0-alpha03"
def hilt_navigation = "1.0.0-alpha03"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_lifecycle_viewmodel"
implementation "androidx.hilt:hilt-navigation-compose:$hilt_navigation"
//GSON
implementation 'com.google.code.gson:gsoenter code heren:2.9.0'
}

Any external dependencies require version checks specified on their official GitHub repo, or their website, if it isn't open-source. Now, as of a quick way to downgrade minSdk, just press Ctrl+Alt+Shift+S within Android Studio, and it'll open the project structure dialog. Find a field that says minSdk, and set it to whatever you require. I recommend setting the targetSdk and compileSdk to the maximum value available, they won't affect your app's deployment on lower api devices. There's also a suggestions pane in the dialog, which can help you update dependency versions studio deems to be out-dated. After having set everything, click Apply/Ok.

Related

Android Studio Arctic Fox Flavor Dimension Issue

It's my first encounter with flavor dimensions. I am trying to compile a ready-made code but somehow I ended up with this issue.
ERROR:
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Affected Modules: app
here is my build.gradle:app
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
id 'kotlin-kapt'
id 'com.google.firebase.crashlytics'
id 'kotlin-android-extensions'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.adit.bangkit.plagroid"
minSdkVersion 23
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary 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
dataBinding true
}
productFlavors {
sandbox {
buildConfigField "String", "BASE_URL", "\"https://plagro.000webhostapp.com/payment.php/\""
buildConfigField "String", "CLIENT_KEY", "\"SB-Mid-client-zS17TygMBI02Ta0o\""
}
production {
buildConfigField "String", "BASE_URL", "\"https://plagro.000webhostapp.com/payment.php/\""
buildConfigField "String", "CLIENT_KEY", "\"Mid-client-GtpJDccjfv7lVXis\""
}
}
}
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 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.android.gms:play-services-location:19.0.1'
implementation 'com.google.firebase:firebase-database-ktx:20.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//Firebase
implementation platform('com.google.firebase:firebase-bom:28.4.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
//glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'com.jakewharton:butterknife:10.0.0'
kapt "com.jakewharton:butterknife-compiler:10.0.0"
annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation "androidx.core:core-ktx:1.7.0"
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2"
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation "io.grpc:grpc-okhttp:1.32.2"
// KTX for the Maps SDK for Android
implementation 'com.google.maps.android:maps-ktx:3.2.1'
// (Optional) KTX for the Maps SDK for Android Utility Library
implementation 'com.google.maps.android:maps-utils-ktx:3.2.1'
implementation 'com.google.maps.android:android-maps-utils:2.2.3'
implementation 'com.firebase:geofire-android-common:3.1.0'
//midtrans payment
implementation 'com.midtrans:uikit:1.28.0-SANDBOX'
}
I am sorry for being a noob and really don't know how to solve this. If someone had a solution please help me with this.this issue happend after i add midtrans payment library.
How to fix this?
According to the link from the error, you should add a flavour dimension. According to the documentation from that link
All flavors must belong to a named flavor dimension, which is a group
of product flavors. You must assign all flavors to a flavor dimension;
otherwise, you will get the build error shown below. If a given module
specifies only one flavor dimension, the Android Gradle plugin
automatically assigns all of the module's flavors to that dimension.
In the example from the link they add
flavorDimensions "version"
And below, in your productFlavor tags you could add
dimension "version"
Or if you don't need more than one dimension you can ignore this last part.

Error message; Cannot access class 'androidx.compose.ui.Alignment.Horizontal'. Check your module classpath for missing or conflicting dependencies

I am making a QR Code Scanner app using Jetpack compose. But when I am trying to use Column, the composable function then the compiler is giving me this error:
Cannot access class 'androidx.compose.ui.Alignment.Horizontal'. Check your module classpath for missing or conflicting dependencies
Here is my app build.gradle module for the app:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.plcoding.qrcodescannercompose"
minSdk 26
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary 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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
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.compose.ui:ui:$compose_version"
// Foundation (Border, Background, Box, Image, Scroll, shapes, animations, etc.)
implementation("androidx.compose.foundation:foundation:1.0.5")
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0'
implementation 'androidx.activity:activity-compose:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// Activity Compose
implementation "androidx.activity:activity-compose:1.4.0"
// CameraX
implementation "androidx.camera:camera-camera2:1.0.2"
implementation "androidx.camera:camera-lifecycle:1.0.2"
implementation "androidx.camera:camera-view:1.1.0-beta01"
// Zxing
implementation 'com.google.zxing:core:3.3.3'
}
Update: This is the code that is generating the error:
I don't know what this error message is saying and how to resolve this?
Make sure to upgrade your version of Compose to the latest stable version which is 1.1.0-rc03
If your project consists of multiple modules, make sure that all of them are using the same version of Compose.

Corrupt serialized resolution result. Cannot find selected module when use firebase ui dependancy

I want to use RecycleView in my android project. For that I tried to add 'com.firebaseui:firebase-ui-database:8.0.0' to my module gradle. After that I am getting an error as "Corrupt serialized resolution result. Cannot find selected module (287) for constraint platform-runtime -> com.google.firebase:firebase-iid:21.1.0"
I am new to android developments and I could not resolve this problem.
Here is my module gradle
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
//id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.bookmark"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true //multidex Error fix
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.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.google.firebase:firebase-firestore:23.0.3'
implementation 'androidx.multidex:multidex:2.0.1' //Multidex error fix
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-database:20.0.2'
implementation 'com.firebaseui:firebase-ui-database:8.0.0'
//implementation 'com.firebaseui:firebase-ui-database:7.2.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation "androidx.cardview:cardview:1.0.0"
//implementation 'com.google.firebase:firebase-firestore:21.4.0'
//implementation 'com.firebaseui:firebase-ui-auth:7.2.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Error disappear when I comment implementation 'com.firebaseui:firebase-ui-database:8.0.0'
Can you give me a solution?
Based on my findings stuff like these are usually caused by corner cases in the dependency graph computation, so changing declaration order or adding / removing dependencies can make the problem go away.
And you should also try Clean project then Rebuild, and/or Invalidate cache and restart.
I had a similar problem and it resolved it.

Android Studio Canary 2020.3.1: Kotlin Unresolved References

After updating my Android Studio Canary version to 3.1, I started receiving Kotlin unresolved references for functions belonging to the kotlin standard library, and the issue also seems to be affecting Android Studio's ability to import the correct library.
I believe my issue is similar to this. Per a recent comment, changing my gradle kotlin version to 1.5.0 fixed the "unresolved reference" issue, but compose beta06 does not support 1.5.0 yet.
I was wondering if anybody had any luck solving this. I believe I have tried to update as many of my dependencies as well as clean building, invalidating cache and restarting.
Here is my gradle file.
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.leetcards"
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'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.4.32'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
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'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
// Navigation
def nav_version = "1.0.0-alpha10"
implementation "androidx.navigation:navigation-compose:$nav_version"
// Accompanist
def accompanist_version = "0.9.0"
// implementation "com.google.accompanist:accompanist-coil:$accompanist_version"
// Networking (Retrofit and Moshi)
def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
def moshi_kotlin_version = "1.12.0"
def moshi_converter_version = "2.9.0"
implementation "com.squareup.moshi:moshi-kotlin:$moshi_kotlin_version"
implementation "com.squareup.retrofit2:converter-moshi:$moshi_converter_version"
// Firebase
implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.firebaseui:firebase-ui-auth:7.1.1'
implementation 'com.facebook.android:facebook-android-sdk:4.x'
// Facebook login
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
// CameraX core library using the camera2 implementation
def camerax_version = "1.0.0"
// The following line is optional, as the core library is included indirectly by camera-camera2
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
// If you want to additionally use the CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
// If you want to additionally use the CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha24"
}
I too have the same problem with Compose project in Android Studio after upgrade to Kotlin 1.5.0. Unresolved references seem to come from the mismatch between Kotlin version defined in project gradle files and Kotlin version bundled with Kotlin plugin. There is some old thread on SO describing similar issue in IntelliJ: link
Summarizing, there are 2 conflicting situations:
Switching to Kotlin 1.5.0 throws error about Jetpack Compose incompatibility;
Downgrading to Kotlin 1.4.32 allows to compile and install the app, however problem with unresolved references arises. Kotlin plugin cannot be easily downgraded (or can it?).
As a temporary measure I am switching between two Kotlin versions, in hope of finding better solution.

Got this error when tried a code using dagger hilt, Error:[Hilt] java.lang.reflect.InvocationTargetException (no error message)

I tried a code to make a currency converter in native Android using an API. I have used Retrofit, Dagger-Hilt and the MVVM architectural design pattern. After doing all the coding ,this is the error I got. The API fetches live currency exchange rates,which were converted from json to kotlin and used.
Gradle file
This is my gradle file with all the dependencies added.
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.currency"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
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{
viewBinding true
dataBinding 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.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//dagger - hilt
implementation "com.google.dagger:hilt-android:2.31-alpha"
kapt "com.google.dagger:hilt-android-compiler:2.28-alpha"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
//Activity KTX for viewModels()
implementation "androidx.activity:activity-ktx:1.2.1"
//Architectural components
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
//Lifecycle
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
//Coroutines Lifecycle Scopes
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
}
like i mentioned in the comments and my github PR. The solution is to use the same version of hilt-android, compiler
I used hilt version 2.33-beta and same version of hilt-android,compiler,but I have encountered the same problem.Then I change the hilt version to 2.3.5 refering to Google codelab,everything is worked because I find that version is incompatible the kotlin version 1.5 or higher.

Categories

Resources