无法使用Gradle构建Android应用程序,但使用sudo除外

Vir*_*ual 5 unix ubuntu android gradle android-gradle-plugin

我正在尝试使用gradle构建一个简单的'hello world'安卓应用程序.如果我发出命令它会建立好

sudo ./gradlew build - >构建正常

但没有sudo,

./gradlew build - >显示以下错误

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':MyStudioApplication'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':MyStudioApplication:_DebugCompile'.
      > Could not find any version that matches com.android.support:appcompat-v7:+.
        Required by:
            workspace:MyStudioApplication:unspecified

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.621 secs
Run Code Online (Sandbox Code Playgroud)

以下是我的build.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:+'
}
Run Code Online (Sandbox Code Playgroud)

请帮忙

use*_*967 5

在这里暗中拍摄,您可能已经使用 sudo 运行了您的初始 gradle 构建,这可能导致工件被下载并授权到 root 并且您的普通用户无法访问。要测试此假设,您可能需要重命名 gradle 下载依赖项的本地存储库,并以标准用户身份重新运行 gradle。

  • 还要查看 SDK 文件夹中所有内容的权限。如果您使用仅限 root 的权限安装了 Google 存储库,那么当您以非 root 身份构建时,它将无法读取它。 (2认同)