0

When trying to run my app for the first time It does not work. Here is the error message I got and can't resolve it.

Error:FAILURE: Build failed with an exception.

* What went wrong:
Task 'prepareReleaseUnitTestDependencies' not found in project ':app'.

* Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

And this the build.gradle file in my project:

apply plugin: 'com.android.application'

repositories {
    mavenLocal()
    flatDir {
        dirs 'libs'
    }
}

android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.example.android.smth"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        resConfigs "auto"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:design:24.2.0'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}
Chisko
  • 3,092
  • 6
  • 27
  • 45
Firas Omrane
  • 894
  • 1
  • 14
  • 21
  • What is the output of `./gradlew assembleRelease --stacktrace`? – Chisko Nov 12 '17 at 21:55
  • where to run this command? – Firas Omrane Nov 12 '17 at 21:58
  • Check [https://stackoverflow.com/questions/31449533/task-publishapkrelease-not-found-in-root-project/31458855#31458855](this). You need to run those in your operating system console, placed on your project's directory. If you are using Windows replace `./gradlew` for `gradlew.bat` – Chisko Nov 12 '17 at 22:01
  • when running it I got NDK is missing a "platforms" directory. If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to C:\Users\ASUS\AppData\Local\Android\Sdk\ndk-bundle. Incremental java compilation is an incubating feature. FAILURE: Build failed with an exception. * What went wrong: Task 'publishApkRelease' not found in project ':app'. BUILD FAILED Total time: 2 mins 12.823 secs – Firas Omrane Nov 12 '17 at 22:33

1 Answers1

0

A Simple file/invalidate cache / restart can work or try one of the solution below

You can try one of this solution

  1. Upgrade Android Studio to 0.8.7

    • Preferences | Updates | Switch "Beta Channel" to "Canary Channel", then do a Check Now.
    • You might be able to skip this.
      1. Checked the Gradle wrapper (currently 1.12.2; don’t try to use 2.0 at this time).
    • Assuming you don’t need a particular version, use the latest supported distribution

      $ vi ~/project/gradle-wrapper.properties ... distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip

    • This can be set in Android Studio at Preferences | Gradle (but 0.8.7 was giving me ‘invalid location’ errors).

    • The 'wrapper' is just a copy of Gradle for each Android Studio project. It allows you to have Gradle 2 in your OS, and different versions in your projects. The Android Developer docs explain that here.
    • Then adjust your build.gradle files for the plugin. The Gradle plugin version must be compatible with the distribution/wrapper version, for the whole project. As the Tools documentation (tools.android.com/tech-docs/new-build-system/user-guide#TOC-Requirements) is slightly out of date, you can set the plugin version too low (like 0.8.0) and Android Studio will throw an error with the acceptable range for the wrapper.

Example, in build.gradle, you have this plugin:

dependencies {
    classpath "com.android.tools.build:gradle:0.12.+"
}

You can try switching it to the exact version, like this:

dependencies {
    classpath "com.android.tools.build:gradle:0.12.2"
}

and (after recording what version you’re changing from in each case) verifying that every build.gradle file in your project pulls in the same plugin version. Keeping the “+” should work (for 0.12.0, 0.12.1, 0.12.2, etc), but my build succeeded when I updated Google’s Volley library (originally gradle:0.8.+) and my main project (originally 0.12.+) to the fixed version: gradle:0.12.2.

Other checks

  1. Ensure you don’t have two Android Application modules in the same Project

    • This may interact with the final solution (different Gradle versions, above), and cause

      UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define (various classes)

    • To check, Build | Make Project should not pop up a window asking what application you want to make.

  2. Invalidate your caches
    • File | Invalidate Caches / Restart (stackoverflow.com/a/19223269/513413)
  3. If step 2 doesn't work, delete ~/.gradle/ (www.wuttech.com/index.php/tag/groovy-lang-closure/)
    • Quit Android Studio
    • $ rm -rf ~/.gradle/
    • Start Android Studio, then sync:
      • Tools | Android | Sync Project with Gradle Files
    • Repeat this entire sequence (quit...sync) a few times before giving up.
  4. Clean the project
    • Build | Clean Project

you must include your app module in the settings.gradle file

include ':app'

and if it added try to remove it from the settings.gradle file then sync your project

Thecarisma
  • 1,424
  • 18
  • 19