2

In one of my existing projects I already added the following libraries for use annotation shared preference

def AAVersion = "4.6.0"

    dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
    }

Other objects are resolving but it isn't able to put() edit(), getOr() and get(). I manually added the module from below link, but I'm getting the same result

https://github.com/androidannotations/androidannotations

Here is the ISPreferenceUtils class

@SharedPref(value = SharedPref.Scope.UNIQUE)
public interface ISPreferenceUtils {
    @DefaultBoolean(true)
    boolean isFirstTime();

    @DefaultBoolean(false)
    boolean languageSelected();

    @DefaultBoolean(false)
    boolean selected();

    @DefaultString("")
    String selectedLocation();

    @DefaultString(ISConstants.ENGLISH)
    String language();

    @DefaultString("")
    String location();

    @DefaultString("")
    String userName();

    @DefaultString("")
    String userEmail();

    @DefaultString("")
    String sessionId();

    @DefaultString("")
    String apiToken();

    @DefaultString("")
    String mobileNumber();

    @DefaultString("")
    String userImage();

    @DefaultString("")
    String deviceId();

    @DefaultString("")
    String mobile();

    @DefaultString("")
    String userPassword();

    @DefaultInt(0)
    int userId();

    @DefaultInt(0)
    int locationId();

}

preferenceUtils is the object of the ISPreferenceUtils.

Here is my Gradle

def AAVersion = "4.6.0"

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'de.hdodenhof:circleimageview:1.3.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.facebook.android:facebook-android-sdk:4.6.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.pacioianu.david:ink-page-indicator:1.2.0'
    implementation 'com.github.jakob-grabner:Circle-Progress-View:v1.3'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation('com.github.hotchemi:permissionsdispatcher:2.4.0') {
        exclude module: "support-v13"
    }
    annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.4.0'
    annotationProcessor 'com.github.AleksanderMielczarek:AndroidAnnotationsPermissionsDispatcherPlugin:2.0.3'
    implementation 'com.wang.avi:library:2.1.3'
    implementation 'com.google.zxing:core:3.2.1'
    implementation 'com.google.firebase:firebase-database:10.2.1'
    implementation 'com.google.firebase:firebase-core:10.2.1'
    implementation 'com.google.firebase:firebase-crash:10.2.1'
    implementation 'com.google.firebase:firebase-messaging:10.2.1'
    implementation('com.onesignal:OneSignal:3.10.5') {
        exclude group: 'com.google.android.gms'
    }
    implementation 'jp.wasabeef:blurry:2.1.1'
    implementation 'com.github.lzyzsd:circleprogress:1.2.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
    implementation('ch.acra:acra:4.5.0') {
        exclude group: 'org.json'
    }
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true;
    }
    implementation project(path: ':libraries:library')

    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    implementation "org.androidannotations:androidannotations-api:$AAVersion"
    annotationProcessor "org.androidannotations:roboguice:$AAVersion"
    implementation "org.androidannotations:roboguice-api:$AAVersion"
    implementation "org.roboguice:roboguice:3.0.1"
}
apply plugin: 'com.google.gms.google-services'

app-level Gradle

buildscript {
    repositories {
        jcenter()

        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://plugins.gradle.org/m2/' }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.fabric.tools:gradle:1.30.0'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.6'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

allprojects {
    repositories {
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://plugins.gradle.org/m2/' }
        google()
        mavenCentral()
        mavenLocal()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I tried a lot but It's not resolving. Can you pls help me.

enter image description here

Komal
  • 79
  • 1
  • 10
  • Hi, can you post the complete gradle file and also the `PreferenceUtils` source? – Vall0n Jan 20 '20 at 14:24
  • @Vall0n I've edited code can you pls check. – Komal Jan 21 '20 at 05:34
  • Hi @Komal, thanks the `PreferenceUtils` looks fine to me. What about your project structure and the build gradle files? Did you use multiple modules (dynamic-feature, library modules) and where did you put the dependency? Is the `PreferenceUtils` in the same module then the class, where you use the grills (`preferenceUtils.userId().put(0)`)? – Vall0n Jan 21 '20 at 07:32
  • Which version of the `com.android.tools.build:gradle` plugin did you use? – Vall0n Jan 21 '20 at 07:33
  • And try to Build -> Make Project that will invoke annotation processors like AndroidAnnotations – Vall0n Jan 21 '20 at 07:36
  • @Vall0n Pls check my updated code – Komal Jan 21 '20 at 08:01
  • There shall be a generated File `ISPreferenceUtils_` that you should use. (e.g. ` @Pref ISPreferenceUtils_ preferenceUtils;`) See also [here](https://github.com/androidannotations/androidannotations/wiki/SharedPreferencesHelpers#defining-the-preferences) – Vall0n Jan 21 '20 at 08:31
  • @Vall0n ISPreferenceUtils_ file is not generating I've created a demo project but the same thing happened. Underscore(_) file is not auto-created. – Komal Jan 21 '20 at 09:18
  • I've created the object of the ISPreferenceUtils interface @Pref ISPreferenceUtils preferenceUtils; – Komal Jan 21 '20 at 09:25
  • 1
    The generated file will be generated when you execute `Make Project` via Android Studio under the `Build` tab. And try to remove `classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'` from the build gradle because you already use an up to date `'com.android.tools.build:gradle` plugin version. You may also have to add javaCompileOptions depending on buildTypes etc. See [here](https://github.com/androidannotations/androidannotations/wiki/Building-Project-Gradle) – Vall0n Jan 21 '20 at 09:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/206345/discussion-between-komal-and-vall0n). – Komal Jan 21 '20 at 09:37

1 Answers1

1

you may have to add javaCompileOptions in the defaultConfig section of the app gradle file depending on your build types and flavors.

defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29

        // If you have different applicationIds for buildTypes or productFlavors uncomment this block.
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": android.defaultConfig.applicationId]
           }
        }
    }

See also here

Vall0n
  • 1,601
  • 2
  • 14
  • 19