I am trying to implement #Parcelize annotation in kotlin to a data class, but it looks as if I forgot to implement something. Even when I try to import kotlinx.parcelize, Android Studio does not know the parcelize option. I implemented kotlin-parcelize and kotlin version is 1.4.21, which should be okay.
Here are my Gradle files:
plugins {
id 'com.android.application'
id 'kotlin-parcelize'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.benzeneapps.ciphers"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "0.0.1"
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
}
buildFeatures {
viewBinding true
dataBinding true
}
}
dependencies {
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.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.core:core-ktx:1.3.2"
implementation "androidx.room:room-ktx:2.2.6"
kapt "androidx.room:room-compiler:2.2.6"
androidTestImplementation "androidx.room:room-testing:2.2.6"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.2.0"
}
repositories {
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
mavenCentral()
}
Project Gradle File
buildscript {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
How I tried to implement it.
import kotlinx.parcelize.Parcelize
import android.os.Parcelable
#Parcelize
data class Cipher(val id: Int, val name: String): Parcelable
Apply kotlin-android before kotlin-parcelize:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-parcelize'
}
This works for me Add this to your build.gradle file
plugins {
id 'kotlin-android-extensions'
}
Related
I am trying to implement Unsplash API according to this website:
https://unsplash.com/documentation#creating-a-developer-account
But got stuck pretty quickly. I don't know why Gradle refuses to compile so here are some files:
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
maven { url 'https://jitpack.io' }
}
dependencies {
def nav_version = "2.5.2"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (App)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'androidx.navigation.safeargs.kotlin'
id "kotlin-parcelize"
}
android {
compileSdk 33
defaultConfig {
applicationId "com.example.gallery"
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
}
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'com.example.gallery'
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
// Unsplash
implementation 'com.github.unsplash:unsplash-photopicker-android:1.0.1'
// Kotlin
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
// tests
testImplementation "com.google.truth:truth:1.1.3"
testImplementation "android.arch.core:core-testing:1.1.1"
testImplementation 'org.robolectric:robolectric:4.8'
}
All I try to do is to add those lines (from the GitHub specification):
To integrate UnsplashPhotoPicker into your Android Studio project
using Gradle, specify in your project build.gradle file:
allprojects { repositories {
...
maven { url 'https://jitpack.io' } } } And in your app module build.gradle file, replacing x.y.x by the latest tag:
dependencies { implementation
'com.github.unsplash:unsplash-photopicker-android:x.y.z' }
The problem occured(8 similar problem):
Execution failed for task ':gallery:desugarDebugFileDependencies'.
Could not resolve all files for configuration ':gallery:debugRuntimeClasspath'.
Could not find com.github.unsplash:unsplash-photopicker-android:1.0.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
- https://repo.maven.apache.org/maven2/com/github/unsplash/unsplash-photopicker-android/1.0.1/unsplash-photopicker-android-1.0.1.pom
Required by:
project :gallery
This question was asked Here but got no answer...
Add the
maven { url 'https://jitpack.io' }
in setting.gradle(project level)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
//...
maven { url 'https://jitpack.io' }
}
}
I'm trying to connect Firebase with my project in Android studio, but it keeps showing "Could not parse Android Application Module's Gradle config" error. How do I fix it? I have tried many methods by skimming through related posts here, but none worked.
settings.gradle-
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
rootProject.name = "hissss"
include ':app'
build.gradle-
// 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'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.graddle(:app)-
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.his"
minSdk 22
targetSdk 32
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
//coreLibraryDesugaringEnabled false
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '33.0.0'
buildFeatures {
dataBinding = true
}
}
dependencies {
implementation platform('com.google.firebase:firebase-bom:30.3.0')
implementation 'com.google.firebase:firebase-analytics:21.1.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth:21.0.6'
implementation 'com.google.firebase:firebase-database:20.0.5'
implementation 'com.google.firebase:firebase-storage:20.0.1'
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.material:material:1.6.1'
implementation 'com.android.support:multidex:1.0.3'
}
I am trying to implement MapBox SDK to my Android Application. I followed the official documentation but I am getting this error.
Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.mapbox.maps:android:10.6.1.
I have tried following the legacy documentation, but still no luck. I would like to ask if there are any other ways to implement the SDK or did I miss something. TYIA.
Here are my gradle scripts:
build.gradle (Project Level)
buildscript {
ext.kotlin_version = "1.5.31"
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins
{
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1' apply false
}
allprojects {
final def var = repositories
{
google()
mavenCentral()
maven { url 'https://esri.jfrog.io/artifactory/arcgis' }
maven { url 'https://olympus.esri.com/artifactory/arcgisruntime-repo/' }
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = "mapbox"
// Use the secret token you stored in gradle.properties as the password
password = MAPBOX_DOWNLOADS_TOKEN
}
}
}
var
}
subprojects {
afterEvaluate { project ->
if (project.hasProperty("dependencies"))
{
dependencies {
implementation "androidx.appcompat:appcompat:1.4.1"
implementation "com.google.android.material:material:1.5.0"
implementation "com.esri.arcgisruntime:arcgis-android:$arcgisVersion"
implementation "androidx.multidex:multidex:2.0.1"
}
}
project.android {
defaultConfig {
multiDexEnabled true
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
}
}
task clean(type: Delete)
{
delete rootProject.buildDir
}
build.gradle (Module level)
plugins
{
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id 'kotlin-android'
}
ext {
arcgisVersion = '100.13.0'
}
android
{
compileSdk 32
defaultConfig
{
applicationId "com.example.project1"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes
{
release
{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions
{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures
{
viewBinding true
}
}
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.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.google.firebase:firebase-messaging:21.1.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
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-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.gms:google-services:3.0.0'
implementation "androidx.appcompat:appcompat"
implementation "com.google.android.material:material"
implementation "com.esri.arcgisruntime:arcgis-android"
implementation "androidx.multidex:multidex"
implementation 'com.google.android.libraries.places:places:2.6.0'
implementation 'com.mapbox.maps:android:10.6.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
rootProject.name = "proect1"
include ':app'
Here is my app-level gradle file
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.app.myapplication"
minSdkVersion 19
targetSdkVersion 31
versionCode 1
versionName "1.0"
multiDexEnabled true
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 {
dataBinding = true
}
}
kapt {
generateStubs = true
correctErrorTypes = true
}
sourceSets {
main {
java {
srcDir "${buildDir}/generated/source/kapt/main"
}
}
test {
java {
srcDir 'src/test/java'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
kapt "com.android.databinding:compiler:3.2.0-alpha10"
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation 'android.arch.paging:runtime:1.0.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
this is my main gradle file
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
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
}
}
I am trying to implement databinding in recyclerview using kotlin. But it is giving me runtime error
Execution failed for task ':app:kaptDebugKotlin'.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
java.lang.reflect.InvocationTargetException (no error message)
Anyone has faced the same error? I have searched and gone through many links related to this error but all states the use of room library which I am not using and still getting this error.
Any help is much appreicated.
Thanks
Instead of
buildFeatures {
dataBinding = true
}
Try this
buildFeatures {
dataBinding true //<--- for binding the data
viewBinding true //<-- for binding the view
}
I solved this error after updating my
Android studio to
Android Studio Arctic Fox 2020.3.1 Patch 3
and also updated
gradle version to 7.0.3
and
kotlin plugin update to 1.5.20.
Basically I updated all my resources and the error was solved.
Updated gradle files
app-level gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.app.navigationdemoapp"
minSdkVersion 19
targetSdkVersion 31
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'
}
}
dependencies {
implementation "androidx.navigation:navigation-fragment-ktx:2.4.0-beta02"
implementation "androidx.navigation:navigation-ui-ktx:2.4.0-beta02"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
project level gradle
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
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()