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

如何在Android Studio中运行不同的产品风格

  •  35
  • saulspatz  · 技术社区  · 9 年前

    现在,如果我双击其中任何一个,构建将毫无错误地运行到完成,但我不知道如何运行结果。如果我点击屏幕顶部的绿色“Run”箭头,我永远无法运行premium应用程序。

    只有一个条目“app”会导致在连接的设备上安装并运行apk,这就是AdsDebug版本。我想我需要添加一个新的配置,但我找不到任何文档,甚至提到“味道”这个词

    我试着添加一个配置,但我不理解这些问题的含义。我查看了默认应用程序的设置,但它们似乎意义不大。我如何告诉它我想要我的应用程序的高级版本?

    还是我的问题与配置无关?我注意到当我看到 Build/Edit Flavors

    我所做的一切设置的口味是添加这个代码到应用程序级的建设。gradle文件:

    flavorDimensions "dummy"
    
    productFlavors {
        ads {
            dimension "dummy"
            applicationId 'com.example.myApp.ads'
        }
    
        premium {
            dimension "dummy"
            applicationId 'com.example.myApp.premium'
        }
    

    我还需要做什么?

    2 回复  |  直到 9 年前
        1
  •  77
  •   CommonsWare    9 年前

    在Android Studio中打开构建变体工具。默认情况下,它停靠在左侧。

    它将显示项目中的模块列表,每个模块都有一个下拉列表,指示运行按钮将使用的构建变体。

    Android Studio Build Variants tool

        2
  •  0
  •   Er.Prem Singh daksha    5 年前

    解决方案

    1. 如果你想创建不同类型的产品风格(比如不同的url:我们应用程序的开发url、质量url和生产url)

    android {
        compileSdkVersion 30
        buildToolsVersion "30.0.2"
    
        defaultConfig {
            applicationId "com.premsinghdaksha"
            minSdkVersion 17
            targetSdkVersion 30
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
    
        flavorDimensions "client"
        productFlavors {
    // use for production debug and release build
            production {
                dimension "client"
                buildConfigField("String", "BASE_URL", "YourURL")
                //if you want to use string anywhere of app show you define
                // buildConfigField and get value where you want to use.
                buildConfigField("String", "Shop_", "\"Shop1\"")
                // production app name
    
                //if you want change application name  and app icon so you define
                // resValue, manifestPlaceholders and get these value in Manifests file.
                resValue "string", "app_name", "Your production name"
                //production  app icon
                manifestPlaceholders = [
                        appIcon     : "@mipmap/app_icon",
                        appIconRound: "@mipmap/app_icon_round"
                ]
                signingConfig signingConfigs.release
    
            }
            // use for quality debug and release build
            quality {
                dimension "client"
                buildConfigField("String", "BASE_URL", "YourQualityurl")
                buildConfigField("String", "Shop_", "\"Shop2\"")
                //use for quality app name
                resValue "string", "app_name", "quality App name"
                // use for quality app icon
                manifestPlaceholders = [
                        appIcon     : "@mipmap/quality_app_icon",
                        appIconRound: "@mipmap/quality_app_icon_round",
                ]
            }
    // use for development debug and release build
            development {
                dimension "client"
                buildConfigField("String", "BASE_URL", "development url")
                buildConfigField("String", "Shop_", "\"Shop3\"")
                //use for dev app name
                resValue "string", "app_name", "developer app name"
                //use for dev app icon
                manifestPlaceholders = [
                        appIcon     : "@mipmap/developer_icon",
                        appIconRound: "@mipmap/developer_icon_round"
                ]
            }
    
        }
    }
    
    1. 建筑渐变(:app) 在android{}中。
    
        signingConfigs {
                // use for signed apk
                release {
                    storeFile file("../premsingh.jks")
                    storePassword "app@app"
                    keyAlias "key0"
                    keyPassword "app@app"
                    v1SigningEnabled true
                    v2SigningEnabled true
                }
            }
    

    enter image description here