How to import javax.annotation.Nullable? - java

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'
}

Related

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;

Unable to merge dex error after adding library

I've been trying to add the design library but everytime i do it i get this unable to merge dex error
i've tried using different versions of SDK's already and other design versions but it dosen't seem to be working
Here is an image of the error:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:26.0.1'
compile 'com.android.support:design:26.0.1'
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.github.clans:fab:1.6.4'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:recyclerview-v7:26.0.1'
implementation 'id.zelory:compressor:2.0.0'
implementation 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.github.javiersantos:BottomDialogs:1.2.1'
compile 'com.github.mancj:SlideUp-Android:1.0-beta'
compile 'com.github.zcweng:switch-button:0.0.3#aar'
compile 'com.firebaseui:firebase-ui-database:0.4.1'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
}
Sorry for such messy dependencies but i've been trying everything to get this fixed but nothing because i need the design library
I got the same issue and I found the docs that work for me.
Add some config to app/build.gradle:
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.3'
}

How to install lettuce library on Android Studio?

How to install lettuce library on Android studio in Gradle files ?
https://lettuce.io
is there any solution to compile the library ?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0’
}
In the lettuce's getting started section there is a section called For Gradle Users on how to add the library from gradle. I think just adding:
implementation 'io.lettuce:lettuce-core:5.1.3.RELEASE'
would work. You must check if you must adjust your current dependencies and/or modify your proguard rules.
Hope I helped.

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'

Program type already present com.google.gson.FieldAttributes

My android app refuses to build with the following error:
Program type already present: com.google.gson.FieldAttributes
Message{kind=ERROR, text=Program type already present: com.google.gson.FieldAttributes, sources=[Unknown source file], tool name=Optional.of(D8)}
My build.gradle dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
api 'com.github.Steveice10:MCProtocolLib:1.12.2-2'
api 'com.github.Steveice10:OpenNBT:1.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation 'com.google.android.ads.consent:consent-library:1.0.6'
implementation 'com.github.GrenderG:Prefs:1.3' //Propably this cause problem
implementation('com.crashlytics.sdk.android:answers:1.4.2#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true
}}
It probably started to happen when I added com.github.GrenderG:Prefs dependency
Add this line to build.gradle file.
configurations {
all*.exclude group: 'com.google.code.gson'
}
After 3 hours of googling around I finnaly found an Answer:
GPDR compilance library caused the problem
implementation ('com.google.android.ads.consent:consent-library:1.0.6') {
exclude module: 'gson'
}
add this code to your build.gradle(app) -
dependencies {
configurations {
all*.exclude group: 'com.google.code.gson'
}
This should solve your problem.
Add Dependency to build.gradle file
implementation 'com.google.code.gson:gson:2.8.2'

Categories

Resources