代码之家  ›  专栏  ›  技术社区  ›  Sahil

找不到Gradle DSL方法:“setApplicationId()”

  •  0
  • Sahil  · 技术社区  · 7 年前

    Gradle找不到方法setApplicationId(),我正在build.gradle文件中使用以下配置:

     android.applicationVariants.all { variant ->
        def mergedFlavor = variant.outputs
    
        switch (variant.flavorName) {
    
            case "appnameDev":
    
        mergedFlavor.setApplicationId("com.wexer.flavor.devtest")
                break
       }  
    }
    
    
    defaultConfig {
        // These are applied to the manifest, to prevent nasty compat modes, use the latest you can.
        minSdkVersion 19
        targetSdkVersion 28
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
    }
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   IntelliJ Amiya    7 年前

    不要

    def mergedFlavor = variant.outputs
    

    做

    def mergedFlavor = variant.mergedFlavor
    

    你的代码是

    android.applicationVariants.all { variant -> 
        def mergedFlavor = variant.mergedFlavor 
        switch (variant.flavorName) { 
           case "appnameDev": 
           mergedFlavor.setApplicationId("com.wexer.flavor.devtest") 
           break 
    

    然后 Clean-Rebuild-Run.

        2
  •  0
  •   Sahil    7 年前

    以下替代方案对我有效:

      flavorDimensions 'white_label', 'server'
        productFlavors {
          labelOne{
             dimension "white_label"
             applicationId 'com.app.labelOne'
    
         }
    
        labelTwo{
            dimension "white_label"
            applicationId 'com.newapp.labelTwo'
        }
    
    
    //build environments
    
        dev {
            dimension "server"
            applicationIdSuffix ".devtest"
            versionNameSuffix "-dev"
    
        }
        integration {
            dimension "server"
            applicationIdSuffix ".integration"
            versionNameSuffix "-integration"
    
        }
        staging {
            dimension "server"
            applicationIdSuffix ".staging"
            versionNameSuffix "-staging"
    
        }
        live {
            dimension "server"
    
        }
    }
    
    推荐文章