Android Studio build.gradle获取项目绝对路径

通过这个字段

 ${project.rootProject.projectDir}";

如项目根build.gradle中:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        mavenCentral()
        // jcenter() // keeped as anchor, will be removed soon
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    ext {
	    // 定义全局变量,常用于版本管理
	    // 变量在子模块的build.gradle中直接以: $NAME 的形式调用
        RootProjectDir = "${project.rootProject.projectDir}".replace("\\", "/")
    }
}

apply from: NATIVE_DIR +"/build.gradle"

app的build.gradle中:

android {

    defaultConfig {
		...
    }
    ...
    println  "Root project2:   ${RootProjectDir}";
}

输出:
在这里插入图片描述

你可能感兴趣的:(Android,android,studio,android,ide)