Can't run my android app - android

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'
}

A Simple file/invalidate cache / restart can work or try one of the solution below
You can try one of this solution
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.
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
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.
Invalidate your caches
File | Invalidate Caches / Restart (stackoverflow.com/a/19223269/513413)
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.
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

Related

Gradle build error of app after Android Studio 4.1 update

I have updated from Android Studio 4.0 to 4.1. After the update I cannot build my application anymore which worked fine before the update.
When I build the project I am getting the following exception:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compressDebugAssets'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CompressAssetsWorkAction
my\application\path\app\build\intermediates\merged_assets\debug\out
The folder my\application\path\app\build\intermediates\merged_assets\debug\out is empty.
What I tried to do:
Clean and rebuild the project
delete the .gradle and the build folder and clean an rebuild the project
invalidate and restart Android studio
Increased the heap size in gradle.properties to: org.gradle.jvmargs=-Xmx4096m
Increased the compileSdkVersion and targetSdkVersion
Installed and updated the buildToolsVersion from 30.0.0 to 30.0.2
Added multiDexEnabled true to my config
My gradle configuration looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-R'
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "my.application.id"
minSdkVersion 23
targetSdkVersion 29
versionCode 2
versionName "1.1"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.multidex:multidex:2.0.1'
}
Guys, I am out of ideas as I am no expert when it comes to gradle. Help would be most appreciated.
I found a temporary solution in downgrading my Android Studio version to 4.0.2.
Additionally, I changed the Android gradle plugin version to 4.0.2 and the gradle version to 6.1.1 which I had installed before. You can do this under File -> Project Structure -> Project.
Now I am able to run my application again. I am aware that this is only a temporary solution but at least I can work again on my application.
I will try to install Android Studio 4.2 Canary 15 the next days and check, if this works for me. I let you know.
This is what usually works for me every time i make an update, I hope it works for you.
Sometimes gradle build fails because, downloading some dependencies required by gradle for a successful build are missing and need to be downloaded. So make sure your computer is online.
-> Click on gradle (right side of your android studio), then toggle the highlighted button in the pic below.
Make sure its not highlighted, Cause if it is highlighted that means gradle is offline (has no access to internet)
Then rebuild project to download the missing gradle dependencies.
I hope you find this useful.
this solution may help. I had problems with this error showing up and I had no idea why. As it turns out, I save my android projects to a USB stick. The USB stick is formatted using PAL. I reformatted using NTFS and the problem has gone.
I had a similar problem this morning after updating my Android studio. In my case, previous projects run well but if I create a new project and attempt to run, I will get the said error message. I changed the Android Gradle plugin version to 4.0.2 and the Gradle version to 6.1.1 from the project structure dialog and I was able to run the app successfully afterward.
I have this problem when I try to build apk with capacitor Ionic in Android Studio. My solution was:
First change the Android Gradle plugin in build.gradle to classpath 'com.android.tools.build:gradle:4.0.2' and in gradle-wrapper.properties change Gradle version to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip and press Sync Now.
When gradle sync is finish, close Android Studio Editor and go to project folder and inside android delete .idea and .gradle folders. Next you need to open PowerSheel in this location and run the code .\gradlew clean.
Finally, you can open the project with android studio using in vs npx cap open android or as you want, wait for sync gradle and then you can build your apk.
Changing the location my projects from a FAT32 formatted drive to an NTFS drive solved the problem for me.

Monkey Talk with Android Studio Error:Execution failed for task ':app:compileDebugJava'

I am following this tutorial to make monkeytalk agent build so that i can record the event and write some test cases. I have also downloaded git project with is running but is not showing in monkey talk IDE and no events are recording.
I have also made my own project and follow all the steps from 1 to 9. I am testing it on real device so I skipped 10th step. The issue I am facing is that when I sync the project the gradle is building properly but when I am running the project it give me following error.
Error:Execution failed for task ':app:compileDebugJava'.
No such property: bootClasspath for class: com.android.build.gradle.AppPlugin
If anyone have any idea, your help is appreciated. Thanks!!!
After try lots of things i at last successfully integrated MonkeyTalk agent in my APK using Android Studio, here are some details steps that would help a lot.
Tip :
used gradle build version 1.0.0, although 1.2.3 is available but there are some issues with that version of gradle and the monkeytalk client agent apk.
if you are using google play services use 7.0.0 version
Steps :
For steps you can refer to this document
but here are few problems that I face when following this post, here are the following :
make libs folder in your app folder and put monkeytalk-agent-2.0.10.jar there, in your app build.gradle use this
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
....
}
no need of using
monkeytalkCompile fileTree(dir: 'monkey-libs', include: ['*.jar'])
this give me error when i am running the project
no need of writing
monkeytalk.initWith(buildTypes.debug)
monkeytalk {
applicationIdSuffix ".monkey"
}
just use this :
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
i think this will help, if anyone is facing problem please let me know. My build is successfully running on monkeytalk IDE
Instead of AspectJ plugin - com.uphyca.gradle:gradle-android-aspectj-plugin:0.9.5' try to use https://github.com/Archinamon/GradleAspectJ-Android.
First add a maven repo link into your repositories block of module build file:
maven { url 'https://github.com/Archinamon/GradleAspectJ-Android/raw/master' }
Add the plugin to your buildscript's dependencies section:
classpath 'com.archinamon:AspectJ-gradle:1.0.15'
Apply the aspectj plugin:
apply plugin: 'com.archinamon.aspectj'
Now build your project and run.
Note: above changes are there only for step#3 and step#5. other steps will be same.

How to use Google Play Services 7.3.0 on AndroidStudio?

I've updated my Android SDK and also the PlayServices Library. Nothing seems to work right now.
The import com.google.android.*; does not exists, and I've added the 'compile' lines on the Gradle File.
Have someone experienced this? How can I solve this?
EDIT
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.gson:gson:2.3'
compile 'org.roboguice:roboguice:3.0.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
That's the Gradle File for a Module.
If you use Android Studio and want to use the latest Google libraries via Gradle dependency, you will have to update the
You can do this via Tools -> Android -> SDK Manager -> You have to update the stuff under Extras
Also make sure that you are not using the Offline Mode of Gradle. You can find this option via (I did this on a Mac) Android Studio -> Preferences -> Gradle -> (Global Gradle Settings) Offline Work
Make sure this option is not checked.
Something which was mentioned by #CommonsWare already (and i add it just to sum up this answer) is to sync the project via the Gradle files. You can do this via the toolbar as seen here:
Or via the menu Tools > Android > Sync Project with Gradle Files
If nothing of the above is working for you, it would be really helpful if you can try to build the project via the command line or the terminal with the following command:
gradle clean build --debug
and then post the output here. It will hopefully show why it can't resolve the library.
Try Tools > Android > Sync Project with Gradle Files and see if that clears up your problem. There's a bug where Android Studio does not always warn you to do this with the yellow banner on the editor.

Android Studio, Fire TV - Issues compiling with Amazon SDK

I'm still exceptionally new to Android Development, about 2 weeks in to my first project. So, a resolution may be obvious, and I can only hope this eventually helps another in my shoes.
The goal was to build an app for FireTV that would stream media (on-demand or live video stream).
I started research on Amazon's developer portal, downloaded AS, Amazon SDK, and anything else I was told I would need to continue. My first thoughts were to familiarize myself with Lollipop, using Google TV's for emulator, and using the TV Activity template, which from what I see is heavily based on the Leanback library. I built and tested and modified to my hearts content, and had a working app, using emulators that can handle api21. Then came the time to 'retro-fit' what I had working with Amazon's Fire TV sdk Add-On (API 17). Learned a bit about AppCompat and a few other errors along the way, most I could figure out on my own. But now, I'm stuck.
Gradle won't compile now that I'm using the FireTV add-on, and the console output isn't helpful to me, at this level.
" What went wrong:
Execution failed for task ':app:processDebugResources'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\path\to\sdk\build-tools\21.1.2\aapt.exe package -f --no-crunch -I C:\path\to\sdk\platforms\android-17\android.jar -M C:\path\to\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -I C:\path\to\sdk\add-ons\addon-amazon_fire_tv_addon-amazon-17\libs\notification.jar -I C:\path\to\sdk\add-ons\addon-amazon_fire_tv_addon-amazon-17\libs\gamecontroller.jar -S C:\path\to\app\build\intermediates\res\debug -A C:\path\to\app\build\intermediates\assets\debug -m -J C:\path\to\app\build\generated\source\r\debug -F C:\path\to\app\build\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.d53e.rbeal.fntsysportsnetwork -0 apk --output-text-symbols C:\path\to\app\build\intermediates\symbols\debug
Error Code:
1
Output:
ERROR: Asset package include 'C:\path\to\sdk\add-ons\addon-amazon_fire_tv_addon-amazon-17\libs\notification.jar' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.*
"
Been stuck here for two days, running short on time and am urgently needing progress. Can't figure out how to include --stacktrace or --info as suggested.
In panic, i tried to port the project to eclipse, and as an end result am stuck with "Cannot Resolve 'R'" errors, the only fix I can find is to change the build target, but I think I need to use Amazon's.
I'd rather use Android Studio, but at this point any help would be greatly appreciated.
build.gradle
apply plugin: 'com.android.application'
android {
// compileSdkVersion 21
compileSdkVersion "Amazon.com:Amazon Fire TV SDK Addon:17"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.d53e.myname.appname"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:leanback-v17:21.0.2'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.amazon.device.tools.build:gradle:1.0.0'
}
(project) build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.amazon.device.tools.build:gradle:1.0.0'
//classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
One of those moments where i want to slam my head against a wall...
Manually copy the file into the "projectName/app/libs" folder,
Change the project explorer view to project, so you can see the libs folder
Right click on the item[s] within, and select "Add as Library"
Much like that last step in eclipse.

Add support library to Android Studio project

I just installed the new Android Studio and I'm looking for a way to import the support library for Android.
Where is the option for that? In Eclipse that are just two clicks. I googled for it but found nothing. Surely it is too new.
=============UPDATE=============
Since Android Studio introduce a new build system: Gradle. Android developers can now use a simple, declarative DSL to have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line.
Edit your build.gradle like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.+'
}
NOTES: Use + in compile 'com.android.support:support-v4:21.+' so that gradle can always use the newest version.
==========DEPRECATED==========
Because Android Studio is based on IntelliJ IDEA, so the procedure is just same like on IntelliJ IDEA 12 CE
1.Open Project Structure (Press F4 on PC and Command+; on MAC) on your project).
2.Select Modules on the left pane.
3.Choose your project and you will see Dependencies TAB above the third Column.
4.Click on the plus sign in the bottom. Then a tree-based directory chooser dialog will pop up, navigate to your folder containing android-support-v4.jar, press OK.
5.Press OK.
I no longer work on Android project for a while.
Although the below provides some clue to how an android studio project can be configured, but I can't guarantee it works flawlessly.
In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It's not true in the other way round, IDE changes normally will not affect the build file.
Since most Android projects are built by Gradle,
it's always a good idea to understand this tool.
I'd suggest referring to #skyfishjy's answer, as it seems to be more updated than this one.
The below is not updated
Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn't play nicely in term of configuring from GUI.
As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.
Assuming you have a Test Project > Test structure.
The build.gradle file you're looking for is located at TestProject/Test/build.gradle
Look for the dependencies section, and make sure you have
compile 'com.android.support:support-v4:13.0.+'
Below is an example.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
You can also add 3rd party libraries from the maven repository
compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
The above snippet will add gson 2.2.4 for you.
In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.
This is way more simpler with Maven dependency feature:
Open File -> Project Structure... menu.
Select Modules in the left pane, choose your project's main module in the middle pane and open Dependencies tab in the right pane.
Click the plus sign in the right panel and select "Maven dependency" from the list. A Maven dependency dialog will pop up.
Enter "support-v4" into the search field and click the icon with magnifying glass.
Select "com.google.android:support-v4:r7#jar" from the drop-down list.
Click "OK".
Clean and rebuild your project.
Hope this will help!
You can simply download the library which you want to include and copy it to libs folder of your project. Then select that file (in my case it was android-support-v4 library) right click on it and select "Add as Library"
In Android Studio 1.0, this worked for me :-
Open the build.gradle (Module : app) file and paste this (at the end) :-
dependencies {
compile "com.android.support:appcompat-v7:21.0.+"
}
Note that this dependencies is different from the dependencies inside buildscript in build.gradle (Project)
When you edit the gradle file, a message shows that you must sync the file. Press "Sync now"
Source : https://developer.android.com/tools/support-library/setup.html#add-library
Android no longer downloading the libraries from the SDK manager, it has to be accessed through Google's Maven repository.
You will have to do something similar to this in your build.gradle file:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
...
compile "com.android.support:support-core-utils:27.0.2"
}
Find more details about the setting up process here and about the different support library revisions here.
AndroidX[About]
implementation 'androidx.appcompat:appcompat:1.0.2'

Categories

Resources