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'
Related
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.
I wanna use RxJava binding APIs for Android UI widgets in my project.
Therefore following the guidance as per this site 'https://github.com/JakeWharton/RxBinding'
But I am unable to import any Android UI widgets in my Kotlin File.
Where as its working fine if I am consuming these widgets in Java File.
Hence, not been to find the actual of this issue.
For reference following are the gradle file and class files(both kotlin and java) using in same project
build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-alpha01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//RxBinding
implementation 'com.jakewharton.rxbinding3:rxbinding:3.0.0-alpha2'
}
BindingExample.java class
RxBindingExample.kt class
Have tried exploring this issue on S.O. but questions or solutions are available for previous version of lib 'com.jakewharton.rxbinding2:rxbinding'
Check this reference:
https://github.com/JakeWharton/RxBinding/blob/master/rxbinding/src/main/java/com/jakewharton/rxbinding3/widget/TextViewTextChangeEventObservable.kt
There are different ways to use depending on the language, note the #file:JvmName("RxTextView") at the start. If you're using java the class RxTextView is visible, in kotlin you should use the extension functions provided by the lib, textChangeEvents() is an example of it.
like that, this will aquire the observable e.g.:
val someTextView = TextView(context)
someTextView.textChangeEvents()
Edit:
Seems that the old class that I've referenced was deleted, here is another one:
https://github.com/JakeWharton/RxBinding/blob/master/rxbinding/src/main/java/com/jakewharton/rxbinding4/widget/TextViewAfterTextChangeEventObservable.kt
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 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/>
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'