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并且它工作正常。 –