2016-08-02 112 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,沒有問題。