In my Activity.kt class, the synthetic isn't being recognized in the import
import kotlinx.android.synthetic...
I have included the following in my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
When trying it import, it will recognize extensions and parcel
import kotlinx.android.extensions...
import kotlinx.android.parcel...
So why is synthetic the only one not being recognized?
Other info:
I have tried invalidating caches and restarting.
I have another computer that also has this android studio project (Same gradle versions and everything). Everything works fine there.
Edit:
I understand the current way to do it is to use data binding. But this is just a project we need to sustain, not improve and upgrade. We have a custom sdk (added many years ago) in the project that is making it hard to upgrade gradle and modernize.
The project, even though synthetic is not recognized, is building and uploading fine. I just want to remove these red lines of error.
Any advice on how to start trouble shooting would be greatly appreciated.
Synthetics were deprecated and removed in the latest version of Android Studio (Chipmunk). The recommendation is to migrate to using view binding. If you cannot do that, then you'll need to use an older version of Android Studio.
Migrating to view binding from synthetics is generally straightforward, so that's the better long term solution of course, but changing the IDE version is a quick short term solution.
Even projects in maintenance mode require occasional maintenance - like dealing with deprecations.
Related
I was trying to migrate build.gradle files to use Kotlin DSL. Using the plugins block instead of apply (legacy, apparently) doesn't seem to be as straightforward as suggested. Since "com.google.firebase.appdistribution", "com.google.firebase.crashlytics", and "com.google.gms.google-services" are missing in the Gradle plugin portal (?). Can I not use them in the plugin block? I tried this but it didn't seem to work. Also, why are they missing? I still don't quite understand how this works so please bear with me.
My project's migration to View Binding is underway but in the meantime this warning is distracting when looking at build logs
Warning: The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin.
How can I disable it?
I also recently faced this problem and found out.
In Kotlin 1.4.20-M2, JetBrains deprecated the Kotlin Android Extensions compiler plugin in favor of View Binding, and Also, Google is promoting modularisation, but synthetic properties don’t work cross-module.
So to fix this warning. Remove apply plugin: 'kotlin-android-extensions' in your build.gradle file
Note: If you're using Parcelize.
Don’t forget that the Parcelize feature in Kotlin is part of the kotlin-android-extensions compiler plugin, so removing the plugin will end up making all your Parcelable classes not compiling if they depend on the Parcelize annotation.
JetBrains extracted the Parcelize from Kotlin Android Extensions to a new plugin, kotlin-parcelize
First, you will need to add kotlin-parcelize plugin to your project build.gradle file.
Plugins {
...
id 'kotlin-parcelize'
}
Then change your old import statement from
import kotlinx.android.parcel.Parcelize
to
import kotlinx.parcelize.Parcelize
For more info, I recommend you to read this Blog Migrating the deprecated Kotlin Android Extensions compiler plugin
Just you need to remove this line from your Gradle:
apply plugin: 'kotlin-android-extensions'
Follow the steps:
kotlin-android-extensions is deprecated so replace it from kotlin-parcelize
If there is #Parcelize annotation used for model classes so you have to replace its import from kotlinx.android.parcel.Parcelize to import kotlinx.parcelize.Parcelize
The report is a warning that you are using a deprecated plugin, I don't understand why you would want to disable it since sooner or later I expect the compile will fail and you may not remember why.
The article says: "If your app does not use Parcelize features, remove the line that enables Kotlin Android Extensions: (aka, just remove the line apply plugin: 'kotlin-android-extensions'). It may turn out you don't need the plugin, hard to say since you didn't indicate if you are using any features supplied by the deprecated plugin.
If you are annotating any classes with 'Parcelable' then there is a bit or work you will need to do, as indicated in the article.
Edit: also gone is view synthetics (the feature that allowed you to not use all those 'findViewById'. that's (IMO) is the larger loss and I have not yet ported my apps over so I cannot comment on the amount of work it will take to move.
For the immediate future, I've chosen to wait and implement the new code later but you will need to make your own decision as to when it's appropriate to migrate away from the deprecated plugin.
I would like to start using Realm for android but i having problem setting it up. i follow the instructions located at https://realm.io/docs/java/latest/#getting-started but still doesnt work.
here is my gradle(project)
here is my gradle (app)
i create a class and extend RealmObject, android studio complains and give me message "Cannot revolve symbol Realmobject". here is a snaphot of my class
my gradle are syncing up fine and there is no error while syncing but for some reason i am not able to start coding Realm object. can someone help me and tell me what i am doing wrong? im using android studio 3.1.3
the problem is that apply plugin: 'realm-android'
also needs to be added to gradle(feature) file
I'm trying to use SQLDelight in my project. Everything seems to be working alright in respect of code generation. Unfortunately I can't use the interfaces generated under /build/generated/source/sqldelight/... in my project. When I try to create a class implementing a generated model it gets underlined with the error cannot resolve symbol 'InterfaceName'.
I prepared an example project showcasing my problem here. Any help getting it to work is of course much appreciated.
You need to apply the sqldelight plugin on the app, not the project. In your application build.gradle file, right below apply plugin 'com.android.application:' put apply plugin: 'com.squareup.sqldelight'
I am currently migrating an Android project from classic IntelliJ IDEA format to Gradle. In my project, there are modules that are using the Android SDK without being Android modules. They are plain Java modules that use the Android SDK instead of a JDK.
How can I achieve that with Gradle?
The approach I can think of is to apply plugin: 'java' and somehow configure the Android SDK as the used JDK or as a dependency. But I don't know how to do it exactly...
I have just revisited Eugen's first hint and "suddenly" it works.
So, basically you need to apply the Java plugin and add Android as a provided dependency.
apply plugin: 'java'
configurations {
provided
}
dependencies {
provided 'com.google.android:android:2.2.1'
}
#Eugen: Maybe you'd like to repost this to receive your credits.