我一直在做一个个人项目,但在过去的几天里,构建并没有更新我的 R.java。我不确定是什么原因造成的。我没有在 XML 资源中看到任何语法错误,但它确实起作用的一次是几天前我手动生成它时(app:generateDebugResources
),当时项目中唯一的资源在 res/raw 下, 一个 HTML 文档。从那时起,我已经编写了我正在实现的公认最小功能所需的大部分内容,并删除了 R.java 以解决问题。Android Studio 唯一剩下的似乎有兴趣抱怨的是unrecognized symbol 'R'
. 我觉得我碰壁了;我将发布我的 XML 以及构建配置和设置。我愿意接受任何关于 Gradle 可能无法打包我的资源的建议,以及建设性的批评。进程内构建被禁用。
设置.gradle:
include 'app'
//include 'nanohttpd'
project(':app').projectDir = new File('app')
//project(':nanohttpd').projectDir = new File('nanohttpd')
构建.gradle:
apply plugin: 'java'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
project(':app') {
dependencies {
}
}
/*
project(':nanohttpd') {
dependencies {
}
}
*/
:app:build.gradle:
apply plugin: 'com.android.application'
repositories {
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "24.0.1"
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile project(':nanohttpd')
compile group: 'commons-codec',
name: 'commons-codec', version: '1.10'
compile group: 'org.nanohttpd',
name: 'nanohttpd', version: '2.3.0'
}
sourceSets {
main {
java {
srcDir 'src/java'
}
resources {
srcDir 'src/res'
}
manifest {
srcFile 'src/android-manifest.xml'
}
}
}
defaultConfig {
minSdkVersion 16
targetSdkVersion 16
applicationId "site.wyrxce.httpclip"
}
buildTypes {
release {
minifyEnabled true
//signingConfig signingConfigs.release
proguardFile getDefaultProguardFile('proguard-android.txt')
}
debug {
initWith release
applicationIdSuffix ".debug"
signingConfig null
debuggable true
}
}
}
src/res/xml/prefs_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="PreferenceScreen_main">
<SwitchPreference
android:key="SwitchPreference_runServer"
android:defaultValue="false"/>
<EditTextPreference
android:key="EditTextPreference_hostPort"
android:defaultValue="3939"
android:numeric="integer"
android:maxLength="5"/>
</PreferenceScreen>
src/res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="bad_request">Unrecognized input</string>
<string name="bad_passwd">Invalid credentials</string>
<string name="internal_err">Internal server error</string>
<string name="clipboard_desc">HTTPClip Input</string>
<string name="toasttext_serverstarted">
HTTPClip service now listening</string>
<string name="toasttext_serverstopped">
HTTPClip Service stopped</string>
<string name="title_switchpreference_runserver">
Run HTTPClip service</string>"
<string name="title_edittextpreference_hostport">Host Port</string>
<string name="summary_edittextpreference_hostport">
Listening port for HTTP Daemon</string>
</resources>