package androidx.appcompat.widget does not exist Android Studio - java

I have created a custom Class which extends ImageView. It was working perfectly fine until AndroidX shows up.
Here, the java code
import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.widget.RelativeLayout;
import androidx.appcompat.widget.AppCompatImageView;
public class CloseView extends AppCompatImageView {
public CloseView(Context context) {
super(context);
init();
}
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Android shows 2 errors for this file
error: cannot find symbol class AppCompatImageView
error: package androidx.appcompat.widget does not exist
Has anyone able to fix this issue?

You should completely migrate to AndroidX to use its classes
Enable AndroidX in Gradle settings:
android.useAndroidX=true
android.enableJetifier=true
Replace dependencies
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
instead of
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
See: https://developer.android.com/jetpack/androidx/migrate
Edit:
AndroidX is the newest replacement to all the previous numbered support libraries. Read more about it here before you start using it.

Related

Mapbox services refuses to import

I have the following in my app build gradle:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "com.mapbox.navigation:ui:1.4.0"
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.11.0'}
and have successfully run things such as a map and placing markers down etc. However, when I go to import anything from services, such as import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher; Android Studio cannot find anything. I've tried different versions in case the imports I needed were deprecated but to no avail. Any ideas? All the tutorials and example code in the documentation and third-party all use these imports and I don't really see a way around them.
Thanks!
In the module-level build.gradle file, add the following dependencies:
// in addition to the rest of your build.gradle contents
// you should include the following repository and dependencies
repositories {
mavenCentral()
maven { url 'https://mapbox.bintray.com/mapbox' }
}
dependencies {
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6'
}

How to add Recycler view in android studio

I am not able to use the RecyclerVeiw class even after adding dependencies in build.gradle(Module:app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
}
No need to add any special dependency
Just update android studio and use it
Even though if you want to make it work through adding dependencies add this
//in xml add this
<androidx.recyclerview.widget.RecyclerView>
// in class add this
import androidx.recyclerview.widget.RecyclerView;
no need to add any dependency
//in xml
<androidx.recyclerview.widget.RecyclerView>
// in class
import androidx.recyclerview.widget.RecyclerView;

cannot resolve symbol for v4 media and app classes

I'm trying to import the following classes for my media player, but my app does not recognize them:
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v7.app.NotificationCompat;
I've tried as others suggested (File->Invalidate Caches/restart), but the error remains.
gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0-rc02'
implementation 'com.android.support:cardview-v7:28.0.0-rc02'
implementation 'com.android.support:design:28.0.0-rc02'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.7', changing: true
}
Add this dependencies to your gradle ;
com.android.support:support-v4:YOUR_VERSION
in long way ;
Project Structure --> Dependencies --> Click Plus sign -> Go to
"Library dependency"
Select which support library "support-v4
(com.android.support:support-v4:YOUR_VERSION)"
Be sure about Android Support Library has been added to your
dependencies.
Rebuild and work it.
Just Add Dependencies in our Gradle File
dependencies {
......
implementation 'com.android.support:support-v4:VERSION'
.....
}
Ex
dependencies {
......
implementation 'com.android.support:support-v4:27.0.1'
.....
}
For android x based projects, add this
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

How to import javax.annotation.Nullable?

I use Android Studio 3.x and Gradle build script.
How can I import javax.annotation.* packages?
Here is my Gradle depedencies example.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
implementation 'com.google.code.findbugs:jsr305:3.0.2'
You can use the following if You olny need annotation feature
implementation "javax.annotation:jsr250-api:1.0"
But need to very careful while using this, Reason being these classes are provided by multiple libraries like
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'javax.inject:javax.inject:1'
implementation 'org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin'
If You are using them already either You don't include that one or use exclude with them to avoid any build errors.
implementation (org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin){
exclude module: 'jsr305'
exclude module: 'jsr250'
}

Cant find library on import statement in Java Class - Android

I'm very new in Android development, and I'm trying to import a library from Github via Gradle. I added a statement in the 'dependencies' section:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
}
But I cannot find the library in my Java class when I try to import it:
import com.squareup...; //Nothing I put here works.
public class MainActivity extends AppCompatActivity {
}
Can somebody point out what I am missing?
Thanks.

Categories

Resources