Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build an Android app with Gradle, except with sudo

I am trying to run a simple 'hello world' android app with gradle build. It builds fine if I issue the command

sudo ./gradlew build --> builds fine

But without sudo,

./gradlew build --> shows following error

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

following is my 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:+'
}

Please help

like image 616
Virtual Avatar asked Jan 10 '14 06:01

Virtual


People also ask

Why is Gradle build failing?

Sometimes due to any issue or after formatting of your pc. Some of the Gradle files may get deleted unexpectedly. So when you will start building your apps you will get to see an error in Android studio as 'Error running android: Gradle project sync failed.

How do I run Gradlew in terminal?

To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … ​ e.g. gradlew clean allTests.

How do I run build Gradle app?

To run a Gradle command, you can simply use the gradlew script found in the root of your project (or gradlew. bat on Windows) followed by the name of the task you want to run. For instance, to build a debug version of your Android application, you can run ./gradlew assembleDebug from the root of your repository.


1 Answers

Taking a shot in the dark here, you may have run your initial gradle build with sudo which may have caused the artifacts to be downloaded and permisionned to root and are not accessible to your regular user. To test this assumption you may want to rename your local repository where gradle downloads the dependencies and rerun gradle as the standard user.

like image 61
user1568967 Avatar answered Oct 20 '22 08:10

user1568967