Cannot resolve android annotation for sharedPreferences - android-studio

I imported this project from eclipse. everything is sorted out but there is this one issue I'm stuck with.
I've a sharedPreference interface which is done using annotations
import com.googlecode.androidannotations.annotations.sharedpreferences.DefaultBoolean;
import com.googlecode.androidannotations.annotations.sharedpreferences.DefaultString;
import org.androidannotations.annotations.sharedpreferences.SharedPref;
#SharedPref
public interface RememberMePrefs {
#DefaultString("")
String email();
#DefaultString("")
String password();
#DefaultBoolean(true)
boolean enabled();
}
when I try to use this interface like this :
#Pref
RememberMePrefs_ rememberMePrefs;
it says "Cannot resolve symbol RememberMePrefs_"
this is my Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "xxxxxx"
minSdkVersion 16
targetSdkVersion 29
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
def AAVersion = '4.6.0'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
apt "org.androidannotations:androidannotations:$AAVersion"
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation files('libs/android-support-v4.jar')
implementation files('libs/androidannotations-api-2.7.1.jar')
implementation files('libs/gson-2.2.2.jar')
implementation files('libs/saripaar-11242012.jar')
implementation files('libs/spring-android-core-1.0.1.RELEASE.jar')
implementation files('libs/spring-android-rest-template-1.0.1.RELEASE.jar')
implementation files('libs/actionbarsherlock.jar')
}
Any help will be appriciated as I've never worked on annotations before.

You are using the latest AndroidAnnotations library in your build.gradle, but importing the old namespace in your Java code.
You should import:
import org.androidannotations.annotations.sharedpreferences.DefaultBoolean;
import org.androidannotations.annotations.sharedpreferences.DefaultString;
import org.androidannotations.annotations.sharedpreferences.SharedPref;
This should be done in other classes as well, probably.

Related

Android studio can't find dependencies android-gif-drawable

i'm trying to import this android-gif-drawable to my project, but even if i did set the emplementation and settings, i can't import or use it.
Here my build.graddle(:app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.androidapp"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
implementation 'com.squareup.picasso:picasso:2.8'
}
And my settings.gradle(AndroidApp)
import org.gradle.api.initialization.resolve.RepositoriesMode
pluginManagement {
repositories {
gradlePluginPortal()
google()
//jcenter()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
//jcenter()
mavenCentral()
//maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
// maven { url 'https://jitpack.io' }
}
}
rootProject.name = "AndroidApp"
include ':app'
But everytime i try to import it or use it i got errors:
import pl.droidsonroids.gif.GifImageView; -> Unresolved reference: pl
<pl.droidsonroids.gif.GifImageView -> Cannot resolve class pl.droidsonroids.gif.GifImageView
I tried to set as specified on the coral page with the "buildscript" before the "plugins" and "allproject" after, but of course i have the error:
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'app\build.gradle'
I can't find a way to make it work or at least see if the library is correctly loaded (but since i don't have an error for the dependency as some other posts, i imagine it found it).
Hum...ok so its's working now...
while it wasn't working i restarted android studio, closed the app, clean and rebuilded the project many time, and it was still not working.
I sleeped, restarted to work ( android wasn't closed) and it worked.. I suposed it was stil loading yesterday when i tried? honnestly i dont get it.
hope this will help someone in the same situation

Unresolved reference: compose in RelayBaseComposable

I tried to import figma designs to Android studio using Relay to Figma tool, but it gave me this error after i fixed my HOME_JAVA problem, which it was telling me that HOME_JAVA invalid directory.
this is my code:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id'com.google.relay' //added to figma
}
android {
compileSdk 32
sourceSets {
main {
assets {
srcDir('src/main/ui-packages') //added to figma
}
}
}
defaultConfig {
applicationId "com.example.figma_layout"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
Unresolved reference: compose in RelayBaseComposable -- this error message indicates that the code is attempting to access the compose function from the RelayBaseComposable class, but this class or function cannot be located.
It seems like the Relay to Figma tool requires the Relay library to be added as a dependency in your build.gradle file, but it's not specified in the dependencies block of the code you provided.
Can you try this? Add this to your dependencies block:
implementation 'com.google.relay:relay:0.1.0'
This should import the Relay library, thus resolving the reference to the compose function mentioned in your error message.

After my Android Studio was upgraded to Arctic Fox version, then can't run emulator correctly in this project, why?

After my Android Studio was upgraded to Arctic Fox version, then can't run emulator correctly in this project, why?
build.gradle(Module)
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id "androidx.navigation.safeargs.kotlin" }
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.squall.doodlekong_android"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
} }
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.recyclerview:recyclerview:1.2.1"
//Scarlet
def scarletVersion = '0.1.12'
implementation "com.tinder.scarlet:scarlet:$scarletVersion"
implementation "com.tinder.scarlet:websocket-okhttp:$scarletVersion"
implementation "com.tinder.scarlet:lifecycle-android:$scarletVersion"
implementation "com.tinder.scarlet:message-adapter-gson:$scarletVersion"
implementation "com.tinder.scarlet:stream-adapter-coroutines:$scarletVersion"
//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
//okhttp3
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
//Easy Permissions
implementation 'pub.devrel:easypermissions:3.0.0'
//Preferences DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0-rc02"
implementation "androidx.datastore:datastore-preferences-core:1.0.0-rc02"
//Dagger Hilt
implementation 'com.google.dagger:hilt-android:2.38.1'
kapt 'com.google.dagger:hilt-compiler:2.38.1'
//Timber
implementation 'com.jakewharton.timber:timber:4.7.1'
def lifecycle_version = "2.4.0-alpha02"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
// Lifecycles only (without ViewModel or LiveData)
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
// alternately - if using Java8, use the following instead of lifecycle-compiler
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
//Coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'
// Navigation component
def nav_version = "2.3.5"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
//Gson
implementation 'com.google.code.gson:gson:2.8.7'
//Lottie
implementation 'com.airbnb.android:lottie:4.0.0' }
build.gradle(Project)
buildscript {
ext.kotlin_version = "1.5.21"
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
def nav_version = "2.3.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
} }
allprojects {
repositories {
google()
mavenCentral()
jcenter()
} }
task clean(type: Delete) {
delete rootProject.buildDir }
build error:
API 'BaseVariant.getApplicationIdTextResource' is obsolete and has
been replaced with 'VariantProperties.applicationId'. It will be
removed in version 7.0 of the Android Gradle plugin. For more
information, see TBD. To determine what is calling
BaseVariant.getApplicationIdTextResource, use
-Pandroid.debug.obsoleteApi=true on the command line to display more information.
I think if you inspect code with lint you will find the solution.
On Windows: gradlew :app:lint
On Linux/Mac: ./gradlew :app:lint
But, i think this error is causing because with Artic Fox new version require another call of arguments... search for call arguments in your code and change to "require_()" signature... for example, in kotlin: in place of "aguments!!", call "requireArguments()"
Hope i help you!

Gradle sync failed: Build file '...\build.gradle' should not contain a package statement

My application was working perfectly fine, I dont know what happened all of a sudden the build.gradle throw an error stating Gradle sync failed, build file '...\build.gradle' should not contain a package statement, the thing is I checked my other apps as well and they had the same package com.example.myapplication;
here is my build.gradle(project:FaceRec);
package com.example.myapplication;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.E;
and here is the build.gradle with in the app
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':openCVLibrary347')
dependencies {
api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}
}
if any further clarification is needed please let me know.
Thanks you very much in advance.
refer to this Android Studio java file gets corrupted
Simply delete your caches should mostly solve your problem.
C:\Users\cc.AndroidStudio3.2\system\caches
Thanks L2_Paver for the guide. I noticed that the build.gradle(project:FaceRec) is having contents that does not make sense, I dont know where and how it was there, so I changed the whole code and pasted an empty project's gradle and added some of the references, now with the replaced code as below the application started to work fine.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Android: Unable to set getContext() in non-static method - requires API Level 23

Below, is some source code which is being called from a non-static method. I'm getting the error
"Call requires API level 23 (current min is 15);
android.app.Fragment#getContext"
android.content.Context context = (Context) getContext();
How can I get the context object?
Under the object explorer > Gradle Scripts > build.gradle, I see this. Looks like version 23 to me. Am I looking in the correct location?
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.test.test"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
Looks like I have Android Studio 1.5.1. I just chose the SettingsActivity project template in Android Studio. And added one class to that default code.
You need to import import android.support.v4.app.Fragment instead of import android.support.app.Fragment;
Pass getActivity() instead of getContext() as Context.
One way to solve was to cast "this" (activity) to (Context) inside the Activity onCreate method.

Resources