遵循these步骤在项目中配置android annotation
个依赖项。官方documentation的链接。
现在在项目中创建了一个sharedPreference
类:
@SharedPref(value = SharedPref.Scope.UNIQUE)
public interface SampleApp {
@DefaultInt(0)
int appOpenedCount();
@DefaultInt(0)
int appOpenedCountVersionSpecific();
}
我正在尝试在android类中访问这些preferences
:
@SuppressLint("Registered")
@EApplication
public class HuntApp extends Application {
private static HuntApp appInstance;
private static Context mContext;
public static SampleApp_ appPref;
@Override
public void onCreate() {
super.onCreate();
appPref = new SampleApp_(this);
}
但它引发了一个错误:
Error:(19, 19) error: cannot find symbol class SampleApp_
我重新确认了依赖项和步骤,但无法构建项目。我在这做错了什么?任何帮助都会很明显。
<?xml version="1.0" encoding="utf-8"?>
<application
android:name=".HuntApp_"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity_"></activity>
</application>
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'android-apt'
def AAVersion = '3.3.2'
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName "com.app.huntapp"
logLevel 'INFO'
logFile '/var/log/aa.log'
}
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.app.huntapp"
minSdkVersion 19
targetSdkVersion 24
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'
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
}
答案 0 :(得分:0)
在build.gradle
中你必须把它放在:
apply plugin: 'android-apt'
并在依赖块中:
apt 'org.androidannotations:androidannotations:4.0.0'
compile 'org.androidannotations:androidannotations-api:4.0.0'
然后,您无法实例化prefs类。你必须使用@Pref
注入它:
@Pref
SampleApp prefs;