getOr、put() 和 edit() 无法在 org.androidannotations 中解析:androidannotations

getOr, put() and edit() can not resolve in org.androidannotations:androidannotations

在我现有的一个项目中,我已经添加了以下库以使用注释共享首选项

def AAVersion = "4.6.0"

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

其他对象正在解析,但无法 put() edit()、getOr() 和 get()。 我从 link 下面手动添加了模块,但我得到了相同的结果

https://github.com/androidannotations/androidannotations

这是 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 是 ISPreferenceUtils 的对象。

这是我的 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'

应用级 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
}

我尝试了很多,但没有解决。你能帮帮我吗

您可能需要在应用 gradle 文件的 defaultConfig 部分添加 javaCompileOptions,具体取决于您的构建类型和风格。

defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29

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

另见 here