0

我有一個完全開發的應用程序。 現在,我只有在mipmap 文件夾和strings.xmlProductFlavours只有資源更改

我在的build.gradle創建產品香精作爲

apply plugin: 'com.android.application' 
    apply plugin: 'sonar' 
    apply plugin: 'sonar-runner' 

    android { 
     useLibrary 'org.apache.http.legacy' 
     compileSdkVersion 23 
     buildToolsVersion "23.0.3" 

     defaultConfig { 
      applicationId "com.example" 
      minSdkVersion 16 
      targetSdkVersion 23 
      versionCode 1 
      versionName "16.1.1.0" 
     } 
     buildTypes { 
      release { 
       minifyEnabled false 
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      } 
     } 
     packagingOptions { 
      exclude 'META-INF/services/javax.annotation.processing.Processor' 
     } 
     productFlavors { 
      flavour1 { 
       buildConfigField "String", "BASE_SERVER_URL", '"http://flavour1.com"' 
       buildConfigField "String", "CITY_ID", "1" 
      } 
      flavour2 { 
       buildConfigField "String", "BASE_SERVER_URL", '"http://flavour2.com"' 
       buildConfigField "String", "CITY_ID", "2" 
      } 
     } 
    } 

    repositories { 

    } 

    dependencies { 
     compile fileTree(include: ['*.jar'], dir: 'libs') 
     testCompile 'junit:junit:4.12' 
     compile 'com.android.support:appcompat-v7:23.3.0' 
     compile 'com.android.support:recyclerview-v7:23.3.0' 
     compile 'com.android.support:support-v4:23.3.0' 
     compile 'com.android.support:cardview-v7:23.3.0' 
     compile 'com.android.support:design:23.3.0' 
     compile 'com.google.android.gms:play-services:8.4.0' 
     compile 'com.squareup.retrofit:retrofit:1.9.0' 
     compile 'de.greenrobot:eventbus:2.4.0' 
     compile 'de.hdodenhof:circleimageview:2.0.0' 
     compile 'com.eftimoff:androidplayer:[email protected]' 
     compile 'com.nineoldandroids:library:2.4.0' 
     compile 'org.apache.commons:commons-lang3:3.4' 
     compile 'com.google.code.gson:gson:2.4' 
     compile 'com.viewpagerindicator:library:[email protected]' 
     compile 'se.emilsjolander:stickylistheaders:2.5.2' 
     compile('org.simpleframework:simple-xml:2.7') { 
      exclude module: 'stax' 
      exclude module: 'stax-api' 
      exclude module: 'xpp3' 
     } 
    compile files('libs/xmlutils.jar') 
    compile 'cc.cloudist.acplibrary:library:1.2.1' 
    compile 'com.github.castorflex.smoothprogressbar:library:1.1.0' 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile files('libs/json-20140107.jar') 
    compile 'uk.co.chrisjenx:calligraphy:2.1.0' 
    compile 'de.greenrobot:eventbus:2.4.0' 
    compile 'com.android.support:multidex:1.0.1' 
    compile 'com.jakewharton:butterknife:7.0.1' 
    compile('com.mapbox.mapboxsdk:mapbox-android-sdk:[email protected]') { 
     transitive = true 
    } 
    compile 'com.github.d-max:spots-dialog:[email protected]' 
    compile files('libs/aws-android-sdk-1.0.4-debug.jar') 
} 

和修改我的文件夾結構

Project 
--/app 
    --/src 
    --/flavour1 
     --/res 
     --strings.xml 
    --/flavour2 
     --/res 
     --strings.xml 
    --/main 
     --/java 
     --/res 
     --/AndroidManifest.xml 
創建具有最小的變化相同的應用程序

然後我得到2個錯誤

`1` 

`error: incompatible types: int cannot be converted to String 
    public static final String PAID_DETAILS = "p"; 
       ^
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
Note: Some input files use unchecked or unsafe operations. 
Note: Recompile with -Xlint:unchecked for details.` 

`2` 

Execution failed for task ':app:compileflavour1DebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

編輯:預期

Project 
--/app 
    --/src 
    --/flavour1 
     --/res 
     --/values 
      --strings.xml 
    --/flavour2 
     --/res 
     --/values    
      --strings.xml 
    --/main 
     --/java 
     --/res 
     --/AndroidManifest.xml 
+0

「公共靜態最後絃樂PAID_DETAILS = 」P以同樣的方式「;」 - 這是在哪裏? – takrishna

+0

在我的課程之一,它沒有任何Productflavours –

回答

2

問題

已更改的文件夾,如下結構的工作是在這裏:

buildConfigField "String", "CITY_ID", "1" 

它會在你的BuildConfig創建:

public static final String CITY_ID = 1; 

它是一個錯誤。

你必須使用

buildConfigField "String", "CITY_ID", "\"1\"" 

在你必須改變buildConfigField "String", "CITY_ID", "2"

+0

罰款工作很高興能得到您的加布裏埃萊馬里奧蒂爵士的答案。你解決了我的問題,但我的琴絃沒有從各自的風味中挑選出來。我創造它們的方式有什麼不妥嗎? –

+0

sry我的壞!!!!!也得到了修正...在res文件夾中使用strings.xml。將其更改爲res-values-strings並且它工作正常。 –