小编eth*_*han的帖子

Gradle defaultConfig vs buildtypes.all vs buildtypes.each

I have search Gradle official website and Android Developer official website, but could not find an answer to this.

  1. In the Andoroid build.gradle, what is the difference between defaultConfig, buildtypes.all, and buildtypes.each. They all seems to have a same effect that set build configuration for different build types (release, debug, etc.)

  2. Why might I use one over the other?

    android {
        ...
    
        defaultConfig {
            ...
        }
        buildTypes {
            release {
                ...
            }
        }
        buildTypes.all {
            ...
        }
        buildTypes.each {
            ... …
    Run Code Online (Sandbox Code Playgroud)

groovy android gradle

7
推荐指数
0
解决办法
957
查看次数

在Android Gradle build.gradle it.buildConfigField中的"it"是什么?

我有搜索Gradle官方网站和Android开发者官方网站,但找不到答案.

  1. 在android build.gradle中,什么是"它".在下面的buildConfigField方法中?这是一个对象的实例吗?

我发现将buildConfigField方法移动到defaultConfig允许我使用没有"it"的方法.

  1. 两者有什么区别?为什么我可以使用另一种方法?

    android {
        ...
    
        defaultConfig {
        ...
    
            buildConfigField 'String', 'API_KEY', MyApiKey
        }
        buildTypes {
            release {
                ...
            }
        }
        buildTypes.all {
            ...
        }
        buildTypes.each {
            ...
    
            it.buildConfigField 'String', 'API_KEY', MyApiKey
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

groovy android gradle

7
推荐指数
1
解决办法
706
查看次数

在Android Android Studio的上下文菜单中添加约束布局障碍

我目前正在阅读ConstraintLayout教程并坚持特定步骤(https://codelabs.developers.google.com/codelabs/constraint-layout/#10).

来源在这里(https://github.com/googlecodelabs/constraint-layout).

根据下面的说明,它表示添加垂直屏障,但我没有在菜单中看到添加选项.实际上整个菜单选项看起来不同."添加垂直屏障"菜单在哪里?

右键单击蓝图或组件树中的ConstraintLayout.您将看到"添加垂直"障碍和"添加水平障碍"选项.

我正在运行Android 2.3.3.

build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.google.googleio"
        minSdkVersion 22
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

android android-studio android-constraintlayout

6
推荐指数
1
解决办法
2174
查看次数

Android Studio构建错误 - "无法解析:监视器"

我有一个以前运行的项目,其中版本升级到最新版本.现在由于下面的构建错误,我无法构建项目.

无法解决:监视
打开文件

"打开文件"链接指向build.gradle(Module)文件.我试过"无效并重新启动"这没有用.

在"无法解决:监视器"或"无法解决:"下搜索未导致任何解决方案.

在这一点上我完全被难住了.

模块:build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.android.sunshine"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support:support-annotations:28.0.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio

3
推荐指数
1
解决办法
2950
查看次数

没有为包中的属性'barrierDirection'找到资源标识符 - ConstraintLayout Barrier

我正在尝试为GitHub上的培训运行一个示例程序(https://github.com/googlecodelabs/constraint-layout).

我更新了build.gradle以修复构建错误,但我无法编译并运行它.我正进入(状态

在"com.google.googleio"包中找不到属性"barrierDirection"的资源标识符

找不到包'com.google.googleio'中属性'constraint_referenced_ids'的资源标识符

我使用的是Android Studio 2.3.3.

build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.google.googleio"
        minSdkVersion 22
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)

activity_main_done.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main_done"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_editor_absoluteX="0dp"
    app:layout_editor_absoluteY="80dp"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="80dp">

    <ImageView
        android:src="@drawable/singapore"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_editor_absoluteX="0dp"
        app:layout_editor_absoluteY="0dp"
        android:id="@+id/header"
        android:scaleType="centerCrop"
        android:contentDescription="@string/placeholder" …
Run Code Online (Sandbox Code Playgroud)

android barrier android-constraintlayout

2
推荐指数
1
解决办法
2125
查看次数