java如何在安卓应用程序中集成安卓注释?
遵循these步骤在项目中配置安卓 annotation
依赖项。官方documentation的链接
现在在项目中创建了sharedPreference
类:
@SharedPref(value = SharedPref.Scope.UNIQUE)
public interface SampleApp {
@DefaultInt(0)
int appOpenedCount();
@DefaultInt(0)
int appOpenedCountVersionSpecific();
}
我试图在安卓类中访问这些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_
我重新确认了依赖项和步骤,但无法构建项目。我做错了什么?任何帮助都是值得的
编辑-1 AndroidManifest。xml
<?xml version="1.0" encoding="utf-8"?>
<application
安卓:name=".HuntApp_"
安卓:allowBackup="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:supportsRtl="true"
安卓:theme="@style/AppTheme">
<activity
安卓:name=".MainActivity"
安卓:label="@string/app_name"
安卓:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity 安卓:name=".LoginActivity_"></activity>
</application>
编辑-2模块梯度文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.安卓.tools.build:gradle:2.1.2'
classpath 'com.neenbedankt.gradle.plugins:安卓-apt:1.4'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'com.安卓.application'
apply plugin: 'com.neenbedankt.安卓-apt'
apply plugin: '安卓-apt'
def AAVersion = '3.3.2'
apt {
arguments {
安卓ManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName "com.app.huntapp"
logLevel 'INFO'
logFile '/var/log/aa.log'
}
}
安卓 {
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-安卓.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
apt "org.安卓annotations:安卓annotations:$AAVersion"
compile "org.安卓annotations:安卓annotations-api:$AAVersion"
compile 'com.安卓.support:appcompat-v7:24.0.0'
compile 'com.安卓.support:design:24.0.0'
}
# 1 楼答案
在
build.gradle
中,您必须放置以下内容:在依赖项块中:
然后,不能实例化prefs类。您必须使用
@Pref
注入它: