Migrate annotation processor to androidX - android

I've a annotation processor for android with following dependencies:
compile 'com.squareup:javapoet:1.10.0'
compile 'com.google.android:android:4.1.1.4'
compile 'com.google.android:support-v4:r7'
In my processor I access Activity and Fragment class. Which includes do I need now to be able to use the new android x Fragment? I can't find anything about this...
I naivly tried adding
implementation 'androidx.fragment:fragment:1.0.0'
// or
implementation 'androidx.appcompat:appcompat:1.0.0'
But this does not help...

On the new AndroidX projects, Fragments import are like this:
import androidx.fragment.app.Fragment
Which means, you should already have added the dependencies and migrated to AndroidX which will show the dependenices like following for example:
implementation 'androidx.appcompat:appcompat:1.0.0'
So, you won't probably need this:
implementation 'androidx.fragment:fragment:1.0.0'

Related

Android SharedPreferences class uses wrong annotation reference

I updated the build.gradle file for an old Android project to use the the new androidx implementation references instead of the old compile references. Throughout the app I had to replace all my import android.support.annotation.Nullable with the new androidx.annotation.Nullable ones. This seems to work fine for the app's own custom codebase.
However, the app also has a SharedPreferences class that uses the android.content.SharedPreferences class. The latter one keeps referencing the old android.annotation.Nullable which gives me a 'Cannot resolve symbol' error now. I included the following implementations in my build.gradle file, I don't know if I'm missing anything to keep this working as it should?
implementation "androidx.appcompat:appcompat:1.0.0"
implementation "com.google.android.material:material:1.0.0-rc01"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'me.dm7.barcodescanner:zxing:1.9.13'
implementation 'me.dm7.barcodescanner:zbar:1.8.4'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.clans:fab:1.6.2'
implementation 'androidx.annotation:annotation:1.1.0'

error: package android.support.v7.widget does not exist

I'm trying to use an SDK given with the RFID scanner I recently bought.
I'm trying to run the sample code given, but it won't compile. I get the following errors on compilation:
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
I've tried all the solutions on similar posts, and I'm pretty sure I have the support library correctly installed.
Here are all my dependencies in my build.gradle (app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.material:material:1.1.0-alpha08'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation project(':Rfid.AsciiProtocol-Library')
implementation 'com.android.support:appcompat-v7:+'
implementation 'com.android.support:recyclerview-v7:26.0.0'
}
I'm new to Android Studio, and as I said I tried pretty much all the answers for similar problems and nothing works. Any help welcome :)
Thanks a lot in advance,
Cyril
You should replace android support recyclerview with androidx
implementation 'androidx.recyclerview:recyclerview:1.0.0'
And you can delete 'com.android.support:appcompat-v7:+' dependency, because you've already import it with
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
It frustrated me for literally hours because the answer here given is missing so much.
In dependencies of gradle:
import:
implementation 'androidx.recyclerview:recyclerview:1.0.0'
click gradle sync (should be a bar on top of the page that pops up
Then in your java file where u actually use the RecyclerView class, import this:
import androidx.recyclerview.widget.RecyclerView;
and you are done
EDIT: So apprently you just need to auto-fill the object you need and android studio will auto inport for you. example:
try to type recyclerview, but press tab to auto-fill it. The object should automatically be imported for you on top of the java page. This works with all android studio objects like view and intent.

Classes using methods of other dependencies is not working in my custom library, any suggestions?

I have created by own library for helper methods & classes also included few other dependencies, then used the jitpack to create a custom dependency. But after implementing it to a project, the classes using the other dependencies are not visible to android studio.
I tried adding the other specific dependencies to the project and it works but I need to find alternative way without the need of adding specific dependencies. If it is possible, please do help.
My Library: My-Utility
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.gms:play-services-location:16.0.0'
If you are expecting any of those implementation dependencies to be automatically visible to apps using your library, replace implementation with api.
See the documentation for more.

After migrating to AndroidX, Error inflating class android.support.design.widget.AppBarLayout

After using Android Studio to migrate my project to AndroidX (and manually fixing a lot of import errors), I'm getting no compile errors but when the app starts I get a crash with:
Error inflating class android.support.design.widget.AppBarLayout.
The offending line in the layout file is:
<android.support.design.widget.AppBarLayout
My dependencies in build.gradle are:
dependencies {
def lifecycle_version = '2.1.0-alpha02'
// used below--will be different for androidx (migrated 2019-02-04)
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha03'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okio:okio:1.15.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'com.jakewharton.rxrelay2:rxrelay:2.1.0'
// Relay class
implementation 'com.jakewharton.rx2:replaying-share:2.1.0'
// ReplayingShare
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
// RxBinding
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" // see def above
// includes ViewModel and LiveData
implementation 'org.apache.commons:commons-lang3:3.8.1'
// for tuples like Triple
implementation 'com.androidplot:androidplot-core:1.5.6'
// AndroidPlot
}
I'm guessing that I'm missing something but I can't find what it is.
You need to use com.google.android.material.appbar.AppBarLayout.
Version 1.0.0 is already out So you can use implementation 'androidx.appcompat:appcompat:1.0.0'
Add dependency implementation 'com.google.android.material:material:1.0.0'
See Material Component integration for latest release version.
And use
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.appbar.AppBarLayout>
For other artifact and Class Mapping see the AndroidX migration Doc.
Please go through this old to new class mappings
eg;- Use com.google.android.material.appbar.AppBarLayout instead of android.support.design.widget.AppBarLayout
For AppBarLayout
For Toolbar
Androidx inflating class <android.support.design.widget.TabLayout/> will not work
it's not exist so replace it with <com.google.android.material.tabs.TabLayout/>
it will work fine
and don't forgot to add
implementation 'com.google.android.material:material:1.1.0-alpha07'
to your dependencies
According to the AndroidX migration docs, the androidx replacement for AppBarLayout is com.google.android.material.appbar.AppBarLayout. Try replacing your AppBarLayout tag with this instead.
As for why compiling/building works, I assume it's something to do with Jetifier, but I'm not certain.
if you are using Kotlin DSL you have to add this to build.gradle.kts
implementation("com.google.android.material:material:1.1.0")
implementation("androidx.appcompat:appcompat:1.1.0")
and in your layout use <com.google.android.material.appbar.AppBarLayout/>

Can't import ViewModel while using Koin library

After, restart Android Studio with invalidate cache, and clean + rebuild build, I still can't import ViewModel class from Koin library. Even forcing manually the import org.koin.android.viewmodel.ext.android.viewModel import.
app / build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "org.koin:koin-android:1.0.2"
implementation 'org.koin:koin-android-viewmodel:1.0.2'
...
}
Anyone with the same problem?
Your activity must extend AppCompatActivity instead of Activity.
If you want to use koin with activities, fragments or services your class must implement implement KoinComponent.
I needed to use AppCompatActivity instead Activity
I had the same issue (also when the Activity extended AppCompatActivity), but in my case, the solution was in using stable version of core-ktx:
// Stable version - Works fine with koin and koin's viewModel
implementation "androidx.core:core-ktx:1.0.1"
// Alpha version - When in use viewModel is not found
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
You don't need Koin library dependency to use by viewmodels method . You only need to ensure that you have these dependencies :
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.0"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.2.0"
implementation "androidx.activity:activity-ktx:1.1.0"
Please follow this android studio guide for more info : https://androideveryday.com/2020/03/07/android-studio-guide-to-viewmodel-livedata-2020-edition/

Categories

Resources