2017-09-11 39 views
0

我有一個4種不同的構建類型的應用程序:調試和發佈(正常的),以及alpha和beta。我的build.gradle聲明類型如下:爲什麼Android Studio試圖在調試包中找到資源而不是主要資源?

buildTypes { 
    // The release (or "live") variant. Application id is app.myapp.live 
    release { 
     minifyEnabled true 
     shrinkResources true 
     debuggable false 

     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     signingConfig signingConfigs.config 

     applicationIdSuffix ".live" 

     ext.enableCrashlytics = true 

     // Build config fields 
     buildConfigField("boolean", "RELEASE", "true") 
    } 

    // The debug variant. Application id is app.myapp.debug 
    debug { 
     minifyEnabled false 
     shrinkResources false 
     debuggable true 

     applicationIdSuffix ".debug" 
     versionNameSuffix '-DEBUG' 

     ext.enableCrashlytics = false 
    } 

    // The alpha variant. Application id is app.myapp.alpha 
    alpha { 
     initWith release 
     debuggable true 

     applicationIdSuffix ".alpha" 
     versionNameSuffix '-ALPHA' 
    } 

    // The beta variant. Closer to live. Application id is app.myapp.beta 
    beta { 
     initWith release 
     debuggable true 

     applicationIdSuffix ".beta" 
     versionNameSuffix '-BETA' 
    } 
} 

我的文件夾結構是正確的,我在不同的構建覆蓋唯一變種的strings.xml(其中應用程序名稱不同)。這一切正常工作。

現在,調試選作構建變量有當,我嘗試引用資源佈局文件,我得到了來自如下:

Error:(16) No resource identifier found for attribute 'arc1Color' in package 'app.myapp.debug'

爲什麼在尋找「app.myapp.debug 「? Java包應該保持不變,只有包ID(和應用程序ID)在構建時在合併清單中應該不同。或者我的想法在這裏錯了?

我使用「com.android.tools.build:gradle:2.3.3」運行AS 2.3.1

+0

感嘆,所以花了很多時間後,我意識到我的佈局有問題。我一起使用數據綁定和領域,這仍然是一個學習過程。 – LaurieScheepers

回答

0

不要包名和應用程序ID混淆的Java包。

When you create a new project in Android Studio, the applicationId exactly matches the Java-style package name you chose during setup. However, the application ID and package name are independent of each other beyond this point. You can change your code's package name (your code namespace) and it will not affect the application ID, and vice versa

和:

Although you may have a different name for the manifest package and the Gradle applicationId, the build tools copy the application ID into your APK's final manifest file at the end of the build. So if you inspect your AndroidManifest.xml file after a build, don't be surprised that the package attribute has changed

更多details here

由於您使用:

debug { 
     applicationIdSuffix ".debug" 
} 

你的包變得'app.myapp.debug'但你的類的java包不會改變。

Error:(16) No resource identifier found for attribute 'arc1Color'

這意味着,在調試版本類型您沒有定義屬性arc1Color(可以是它是在資源中定義的其他構建類型內側)。檢查你的資源文件。

+1

感謝您的信息Gabriele!我發現我的問題(與包無關)。 – LaurieScheepers