2016-08-02 110 views
1

我一直在个人项目上工作,但在过去的几天内,构建并没有更新我的R.java。我不确定是什么原因造成的。我在XML资源中没有看到任何语法错误,但是有一次它做了工作,当时我几天前手动生成它(app:generateDebugResources),并且当时项目中唯一的资源是在res/raw,一个HTML文档。自那时起,我已经写了大量我需要的功能,我正在执行的功能很少,并且在解决问题时删除了R.java。 Android Studio似乎唯一感兴趣的就是unrecognized symbol 'R'。我感觉自己撞墙了;我将发布我的XML以及我的构建配置和设置。对于为什么Gradle可能无法打包我的资源以及建设性的批评,我很乐意提供任何建议。进程中的建筑物被禁用。资源组装失败

settings.gradle:

include 'app' 
//include 'nanohttpd' 

project(':app').projectDir = new File('app') 
//project(':nanohttpd').projectDir = new File('nanohttpd') 

的build.gradle:

apply plugin: 'java' 

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 
    } 
} 

project(':app') { 
    dependencies { 
    } 
} 

/* 
project(':nanohttpd') { 
    dependencies { 
    } 
} 
*/ 

:应用程序:的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 /价值/ 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> 
+0

您是否尝试了gradle clean project/rebuild project –

+0

是的,那里没有运气。自从出现这种情况以来,我尝试过大量的构建。 –

+0

尝试在Android Studio中使缓存失效/重新启动 –

回答

0

问题解决了!我只是手动运行AAPT并检查输出;它直接导致了我在XML资源中犯的一个错误。 Gradle的任务现在生成R.java,没有问题。