android.annotation cannot be resolved IntDef and NonNull - android

I'm trying to run a sample android code in Andriod Studio, but when I try:
import android.annotation.IntDef;
import android.annotation.NonNull;
keep getting an error related to this line like:
the import android.annotation cannot be resolved
Any suggestion will be appreciated

I think it would be better if you work with the support annotations:
add this dependency to your project and see if it works:
compile 'com.android.support:support-annotations:24.2.0'

accourding to this answer you can use
android-sdk/tools/support/annotations.jar - Which includes the following annotations:
SuppressLint
TargetApi
android-sdk/extras/android/support/annotations/annotations.jar - Which includes many other annotations:
AnimRes
AnimatorRes
AnyRes
ArrayRes
AttrRes
BoolRes
ColorRes
DimenRes
DrawableRes
FractionRes
IdRes
IntDef
IntegerRes
InterpolatorRes
LayoutRes
MenuRes
NonNull
Nullable
PluralsRes
RawRes
StringDef
StringRes
StyleRes
StyleableRes
XmlRes

I had faced the same problem and came across this question but was not answered.
I could resolve this issue by following steps mentioned here.
After this, You shall sync the project with Gradle files.
Note: You may not find the same annotation path
e.g. import android.annotation.NonNull; --> import androidx.annotation.Nullable;

Related

Error: cannot find symbol import com.google.android.gms.ads.InterstitialAd

I had added google AdMob to the project and found this error :
error: cannot find symbol
import com.google.android.gms.ads.InterstitialAd;
^
symbol: class InterstitialAd
location: package com.google.android.gms.ads
I found the answer :
add this codes to build.gradle(app)
(in the android tag )
configurations.all {
resolutionStrategy {
force "com.google.android.gms:play-services-basement:17.0.0"
force "com.google.android.gms:play-services-base:17.1.0"
force "com.google.android.gms:play-services-stats:17.0.0"
force "com.google.android.gms:play-services-gcm:17.0.0"
force "com.google.android.gms:play-services-ads:19.7.0"
}
}
and if you had use of admob in the one library add codes above to library gradle too
If you get this error after updating your com.google.android.gms:play-services-ads dependency to a more recent version, know that importing com.google.android.gms.ads.InterstitialAd has been deprecated since version 19.7.0 and has since been totally removed.
The new import should be:
import com.google.android.gms.ads.interstitial.InterstitialAd;
Either revert com.google.android.gms:play-services-ads to a version pre-19.7.0 or update your code by following the documentation here: https://developers.google.com/admob/android/interstitial.

Unresolved reference: RecyclerView when trying to inherit Adapter

I am trying to make a RecyclerView in Android Studio and I am struggling to inherit from RecyclerView.Adapter<>()
This is the fragment of code that contains the problem:
package Adapters
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.R
import android.os.Bundle
import models.Post
class PostAdapter(private val postList: List<Post>, private val content: String) : RecyclerView.Adapter<PostAdapter.PostViewHolder>() {
Android Studio sets "RecyclerView" red and I can't get rid of it. I tried solutions from other posts on stackoverflow, tried to follow tutorials on the internet, but there isn't anything about androidx and I can't use older version (android.support.v7.widget.RecyclerView), because Android Studio won't let me.
I imported RecyclerView in mains build.gradle:
implementation "androidx.recyclerview:recyclerview:1.1.0"
And added google() in the highest-instance build.gradle
I hope I explained the problem properly and you can help me.
I think you are missing import of recycler view
import androidx.recyclerview.widget.RecyclerView
Also If you've just migrated to Android X Android studio might be buggy so you want to do File -> Invalidate Caches/Restart
SOLVED!
Did you remember to specify an id for the recyclerview after adding it to your main activity? If yes, then check to make sure that the id you gave is exactly the same as the red text that's causing an unresolved error. Eg
If in main_activity.xml you have
`<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />`
Then in MainActivity.kt you should have
`recyclerView.layoutManager = StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL)`
The word "recyclerView" should be exactly the same in the 2 files where it is used
In my case, I was using the wrong library version.
My library version was way too greater than the released version.
implementation 'androidx.recyclerview:recyclerview:2.9.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

Error: cannot find symbol variable Constants

How can import util.Constants in
Android Studio 3.0.1
Error:cannot find symbol variable Constants
Alt+enter said me android.provider.SyncStateContract.Constants? But I need to import like
Import mypackage name.until.Constants
delete the Constant usage in the program.
Go to your imports section and enter
import android.provider.SyncStateContract.Constants.ConstantName
This works out.

GRPC for android: Import different protoc file

I'm using GRPC framework for my project. For example here is my sample directory structure for storing protoc file:
main
proto
model
user.proto
include
base.proto
I want to include base.proto into user.proto but I don't know how. I have tried some way to include that such as:
import "include/base.proto"
import "../include/base.proto".
But it doesn't work. I always receive error like:
import "include/base.proto" was not found or had errors.
Please help me figure out this problem.
The correct way should be:
import "include/base.proto";
gRPC uses that type of path in multiple tests.

Using Arcanimator in android app

Hi i want to use ArcAnimator and ArcLayout in one android project .
for that i using this dependencys
compile 'com.ogaclejapan.arclayout:library:1.0.1#aar'
compile 'com.github.asyl.animation:arcanimator:1.0.0'
but i give this error message
cannot resolve symbol'SupportAnimator'
cannot resolve symbol'ViewAnimationUtils'
in import line
import io.codetail.animation.SupportAnimator;
import io.codetail.animation.ViewAnimationUtils;
and its strange because i do not give this error in this lines
import io.codetail.animation.arcanimator.ArcAnimator;
import io.codetail.animation.arcanimator.Side;
which is in same library.
can anyone help me about that?
You have to use other dependency to use Support Animator say https://github.com/kedzie/Support_v4_NineOldAndroids. Support Animator is not there in the package of the library that you have used. It’s not showing inside the package you have used, you can check at https://github.com/asyl/ArcAnimator/tree/master/animator/src/main/java/io/codetail/animation/arcanimator.
Also you can take help of some samples given here at https://github.com/ozodrukh/CircularReveal/releases.

Categories

Resources