标签: android-productflavors

是否可以在android中将颜色资源设为私有?

我想知道是否可以在 android 中拥有私有颜色资源?

例如:主要文件:colors.xml:

  <color name="red">#520A2A</color>
  <color name="red_darken_1">#A11453</color>
Run Code Online (Sandbox Code Playgroud)

风格 1 中的文件:element_colors.xml:

  <color name="header_color">@colors/red</color>
  <color name="footer_color">@color/red_darken_1</color>
Run Code Online (Sandbox Code Playgroud)

风格 2 中的文件:colors.xml:

  <color name="blue">#041B3F</color>
  <color name="blue_darken_1">#244B77</color>
Run Code Online (Sandbox Code Playgroud)

element_colors.xml:

  <color name="header_color">@colors/blue</color>
  <color name="footer_color">@color/blue_darken_1</color>
Run Code Online (Sandbox Code Playgroud)

现在我不希望人们在布局文件中使用颜色或来自 color.xml 的样式,但我总是希望他们从 element_colors.xml 使用它,这样应用程序就不会变得特定于单一风格。基本上,如何使布局和样式无法访问某些颜色文件?

android android-layout android-resources android-productflavors

5
推荐指数
1
解决办法
1239
查看次数

在 Multi Flavor 应用程序中,如何避免重复资源

如果我有 3 种口味 flavor1、flavor2 和 flavor3,每种口味都有 Dev、Pat 和 Prod“子口味”版本,它们的参数不同,但每种主要口味都有不同的资源。

所以我现在有 9 种不同的风格,但只有 3 个不同的资源文件夹)。我希望相同的“子口味”使用相同的资源。

我怎样才能做到这一点?我在关于 flavorDimensions 的文档中看到过,但不确定如何配置资源文件夹。

目前我正在使用类似的东西

sourceSets {

   flavor1_dev{
            res.srcDir  'src/flavor1/res'
        }

   flavor1_prod{
            res.srcDir  'src/flavor1/res'
        }

   flavor2_dev{
            res.srcDir  'src/flavor2/res'
        }

   flavor2_prod{
            res.srcDir  'src/flavor2/res'
        }

}    
Run Code Online (Sandbox Code Playgroud)

android android-gradle-plugin android-productflavors android-flavordimension

5
推荐指数
1
解决办法
3458
查看次数

找不到与包名称 processAppDebugGoogleServices 匹配的客户端

我已经尝试了 Stack Overflow 上几乎所有相关的解决方案。但问题仍然没有解决。

Error: Execution failed for task ':App:processAppDebugGoogleServices'.
> No matching client found for package name 'com.example.application'
Run Code Online (Sandbox Code Playgroud)

设置.gradle:

include ':App'
Run Code Online (Sandbox Code Playgroud)

这是清单代码:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.application"
    android:versionCode="17"
    android:versionName="1.17">
Run Code Online (Sandbox Code Playgroud)

以下是应用程序级别的 Gradle 依赖项:

classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
Run Code Online (Sandbox Code Playgroud)

问题:flavor1,即应用程序,正在生成错误,而 application_rtl 工作正常。

android google-play-services android-productflavors

5
推荐指数
1
解决办法
9997
查看次数

Android Studio 是否支持子口味?

我有一个 Android Studio 项目,目前在 build.gradle 中有 2 种产品风格,如下所示:

productFlavors {
        parent {
            applicationId "xxx.parent"

        }
        teacher {
            applicationId "xxx.teacher"
        }
    }
Run Code Online (Sandbox Code Playgroud)

两种风格在 src/main 下都有一些共同的代码

我需要的是 1 级以上的风味,所以我希望在一种风味下有 1 级定制的子风味(对于某些资源和一些静态变量)

所以我想要类似于下面的东西:

productFlavors {
        parent {
            p1 {
                applicationId "xxx.parent.p1"
               }
            p2 {
                applicationId "xxx.parent.p2"
               }
        }
        teacher {
            t1 {
                applicationId "xxx.teacher.t1"
            }
            t2 {
                applicationId "xxx.teacher.t2"
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以我的目标是拥有 2 种类型的应用程序(老师和家长),每个都可以自定义 n 次(它们会因应用程序 ID、资源文件和静态变量而异)

知道如何实现吗?

android-studio android-gradle-plugin android-productflavors

5
推荐指数
1
解决办法
631
查看次数

android sdk 产品风味 - 当我使用 Intent 开始新活动时未找到活动

我有一个工作应用程序,我添加了 2 种产品口味。这个应用程序在第一个屏幕上有一个菜单,允许用户选择下一个活动,我用意图加载。

这是 AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name="com.alpha.aloedu.MainActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.alpha.aloedu.guideddrawing.GuidedLetterDrawingActivity"
        android:label="Guided Letter Drawing"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.buildvocabulary.BuildVocabularyActivity"
        android:label="Image Plus Word"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findthepicture.FindThePictureActivity"
        android:label="Find the Picture"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.findtheletter.FindTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.fillintheletter.FillInTheLetterActivity"
        android:label="Find the Letter"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.alpha.aloedu.EndActivity"
        android:label="End Activity"
        android:screenOrientation="portrait" />

    <activity
        android:name="com.alpha.aloedu.AdminActivity"
        android:label="Admin Activity"
        android:theme="@style/AppTheme.NoActionBar"
        android:screenOrientation="portrait"
        />

</application>

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:requiresSmallestWidthDp="480"
    android:resizeable="false" …
Run Code Online (Sandbox Code Playgroud)

android android-intent android-gradle-plugin android-productflavors

5
推荐指数
1
解决办法
640
查看次数

如何为具有风味维度的不同产品变体指定签名配置?

之前已经问过这个问题(例如Gradle 签名与风味和维度),但答案似乎不适用于 Gradle 3.5。

使用 2 个风味维度,我为每个发布变体指定了签名配置,如下所示:

signingConfigs {
    klondikeGoogleRelease
    ...
    pyramidGoogleRelease
    pyramidAmazonRelease
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
    }
}

applicationVariants.all { variant ->
    def flavors = variant.productFlavors
    variant.mergedFlavor.setApplicationId flavors[0].ext.applicationId + flavors[1].ext.applicationIdSuffix

    if (variant.buildType.name == "release") {
        variant.mergedFlavor.setSigningConfig android.signingConfigs[variant.name]
    }
    println "Mergedflavor: ${variant.name} signing ${variant.signingConfig.name} ready ${variant.signingReady}"
}
Run Code Online (Sandbox Code Playgroud)

这足以gradle signingReport报告正确的设置,但gradle assemblePyramidGoogleRelease(例如)将构建一个未签名的 apk。

它正在跳过validateSigningPyramidGoogleRelease任务,这反映在gradle tasks --all输出结果中,没有列出validateSigning*任何*Release变体。

android gradle android-productflavors android-flavordimension

5
推荐指数
1
解决办法
739
查看次数

无法更改模块 buildVariant



我有一个带有主应用程序和 3 个模块的项目。他们像彼此依赖

app (android application)
 |
 --- module1 (android library)
       |
       --- module2 (android library)
             |
             --- module3 (android library)         
Run Code Online (Sandbox Code Playgroud)

我将 AS 3.0 与 BuildTool 3.0.0-alpha5 一起使用。

我应用了文档中描述的更改:https : //developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#variant_dependencies


这是我的 build.gradle(应用程序)

apply plugin: 'com.android.application'
android {
    ...
    buildTypes {
        debug {}
        qa {}
        release {}
    }
    flavorDimensions "default"
    productFlavors {
        flavor1 {dimension = "default"}
        flavor2 {dimension = "default"}
    }
}
dependencies {
    ...
    implementation project(path: ':module1')
    ...
}
Run Code Online (Sandbox Code Playgroud)

这是我的 build.gradle ( module1 )

apply plugin: 'com.android.library' …
Run Code Online (Sandbox Code Playgroud)

android android-library android-studio build.gradle android-productflavors

5
推荐指数
1
解决办法
1770
查看次数

如何根据口味更改 Flutter 应用程序名称?

我有 Flutter 应用程序的开发和生产风格。

问题是开发和生产应用程序的标签和启动器是相同的,所以看不出区别。(实际上不能同时安装在设备上)

根据风味更改 Flutter 应用程序名称的简单方法是什么?

我知道可以通过修改 AndroidManifest.xml 和 Xcode info.plist 来更改应用程序标签和启动器。但这并不简单:必须在xml和plist文件中制作额外的文件以供参考。像这样修改有悖于 Flutter 的目的。

有人知道解决方案吗?

谢谢!

xcode android ios android-productflavors flutter

5
推荐指数
2
解决办法
2525
查看次数

配置 Android 构建变体的错误重新声明类

在我的 Android 项目中,我配置了一个包含 3 个变体的维度(例如:mock、dev、prod)。我还有默认的构建类型(调试、发布),我在其中实现了应用程序:

  • src/debug/java/package/MyApplication.kt
  • src/release/java/package/MyApplication.kt

所以我可以生成 6 个构建(mockDebug、mockRelease、devDebug、devRelease 等)

现在我的 mockDebug 变体需要 MyApplication.kt 的特定实现。

当我在这里阅读时 我可以在此路径中创建一个类 MyApplication :src/mockDebug/java/package/MyApplication.kt

但是,我在 Android Studio 中收到一条错误消息,提示“重新声明:MyApplication”。

我确信我可以解决这个问题,将所有调试/发布 MyApplication.kt 实现移入

  • 模拟调试
  • 模拟发布
  • 开发调试
  • 开发版
  • 调试
  • prodRelease

目录,但我不明白为什么文档说这是可能的,即使我收到那个错误

谢谢你帮助我

android gradle build.gradle android-productflavors

5
推荐指数
1
解决办法
2042
查看次数

如何防止特定于风味的单元测试被编译为另一种风味?

我正在尝试这样做,但使用单一维度,因此更简单:如何指定二维风格的单元测试文件夹

app 模块 build.gradle 指定了 2 种风格,免费和高级:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'

    android {
        compileSdkVersion 28
        defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android- 
     optimize.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions 'someFlavor'
    productFlavors {
        premium {
            applicationIdSuffix '.premium'
        }

        free
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        debug.java.srcDirs += 'src/debug/kotlin'
        release.java.srcDirs += 'src/release/kotlin'

        free {
            java.srcDirs += 'src/free/kotlin'
            test.java.srcDirs += 'src/test/kotlin'
        }

        premium …
Run Code Online (Sandbox Code Playgroud)

junit android android-productflavors

5
推荐指数
1
解决办法
731
查看次数