Android x databinding - android

I migrated my project to androidx and now I'm receiving errors for every databinding generated class because all these generated classes still use import android.support.v7 instead of android x. So far I tried to delete all generated classes and rebuild project, but it generates same ones after building project. Does anyone know how to solve it?

Even though you have migrated to AndroidX, as you said your classes are still using the old imports. Android Studio doesn't seem to refactor it well enough for some reason. This happened to me too and I had to manually delete the invalid imports and add the androidx imports. (alt + enter) to add the correct imports after deleting the invalid imports.
Edit: you'll need to change the class imports as well as the full qualified names of the widgets in the xml layout, menu, etc. files.
Change import android.support.v4.app.Fragment;
To
import androidx.fragment.app.Fragment;
Change <android.support.design.widget.CoordinatorLayout>
To <androidx.constraintlayout.widget.ConstraintLayout>

Related

Do not add unused imports when Java is converted to Kotlin

When I paste some Java code into a Kotlin project, Android Studio can convert the syntax. However, when the converter is invoked, it adds several unused imports to the file, which broke my existing code.
import androidx.core.app.ComponentActivity.ExtraData
import androidx.core.content.ContextCompat.getSystemService
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
import android.R
The pasted code snippet doesn't need these imports. Since I already imported my.application.R but AS adds android.R, references to R. will broke.
Why are these added? Is this a bug in the converter? Can I somehow disable it?

Android Studio 3.3.2 use fully qualified name when using "import" action

I'm having some trouble with Android Studio 3.3.2 and Kotlin on Mac. Every time I use the "import" action, the fully qualified name is used in-place instead of the import statement. You can see the behavior in this video:
https://i.imgur.com/Mraz7zs.mp4
I already tried the suggestions given in this other question and they don't seem to work. I also tried reinstalling Android Studio and deleting its configuration, but neither worked.
This behavior for importing generated Data Binding classes occurs when you try to import a class while the project is not yet built. First click on "Rebuild project" and then import the class. Then the import works correctly.

Changing package path from existing imported project

How can I change the entire package path in Android Studio, so that also the import statements within Java classes and xml files will be changed automatically.
I know there are threads already posted about this topic, but whenever I change package path, I have to adapt all import statements by hand. And it's much work when there are over 100 classes :(
If you want to move your Java classes to different package, in Android Studio you can right click on package name and then select Refactor->Move.

Imported library package does not exist in Java project

I created an Android project and imported a library using its source code. I added it as an existing module.
When my project referenced a library class, the IDE offered me to import the package. It did it without problem. I compiled the library and it was okay.
I used this import:
import eu.janmuller.android.simplecropimage.CropImage;
When I compiled again, the source code shows no errors, yet I get these errors:
java: package eu.janmuller.android does not exist java: package
eu.janmuller.android.simplecropimage does not exist
So the IDE offered me the package as it knows it. On second thoughts, it does not.
What should I set?
I renamed the imported module once so when I restarted the IDE, it was marked with a number (CropImage1) but it compiles now. If I rename it again, it won't compile.
NEVER rename anything when dealing with modules!

"The import net cannot be resolved"

I have an Android project in Eclipse that previously had one library imported, zbar. And now something peculiar happened when I added a second library, one which I put together myself. At first, the project wouldn't build because of android-support-v4 mismatch. So I updated the minSDK of my application project to reflect the one in my library. That seems to have worked.
Next, I wanted to make use of my new library, so I created an object of a type defined inside it, and thus had to import the code. What happened next was Eclipse started to complain about one of the imports to zbar.
import net.sourceforge.zbar.Symbol;
And what i don't understand is, it says "The import net cannot be resolved", and only the word "net" is underlined in red. As if it didn't see the period following "net". What's going on here?
I have tried removing the library and then adding it, as well as changing the minSDK version back. Nothing has worked so far.
edit: I think removing the android-support-v4 from my custom library solved this.

Categories

Resources