Running gradle with options in Android Studio [duplicate] - android-studio

I have the following simple build configuration with a task:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
task compileSass(type:Exec) {
commandLine 'sass', "src/main/theme/default.scss", "src/main/assets/default.css"
}
project.afterEvaluate{
preBuild.dependsOn("compileSass")
}
}
The build runs just fine when run from the command line with gradle installDebug but fails when running from Android Studio with the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':PixateTest:compileSass'.
> A problem occurred starting process 'command 'sass''
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
How can I pass the parameters, such as --stacktrace, from Android Studio to Gradle so I can debug why the task fails?

On OSX: Android Studio -> Preferences -> Compiler -> Gradle -> Command-line Options

File > Settings > Gradle > Gradle VM options.
I suspect you're failing compileSass because of "sass" not being on PATH.

Related

How do I resolve this ProductFlavours error

This is the first time I've used Android Studio and I can't build this app.
Can anyone tell me how to fix this code?
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
defaultConfig {
applicationId "org.settingsdeployer"
minSdkVersion 15
targetSdkVersion 21
versionCode 4
versionName "1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
normal {
applicationId "org.settingsdeployer"
versionCode 4
versionName "1.2"
}
french {
applicationId "org.settingsdeployer"
versionCode 5
versionName "1.2_fr"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
I'm getting these errors when it tries to sync:
ERROR: All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Affected Modules: org.settingsdeployer
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: org.settingsdeployer
I made the requested changes and it sync'd but now I can't make an apk:
That's great, it sync'd the build without errors but now when I try to generate an apk i get more errors. I have no idea what I'm doing!
UPDATE:
After adding flavorDimensions it sync'd the build without errors but now when I try to generate an apk i get more errors. I have no idea what I'm doing!. Here is the error log:
Executing tasks: [:org.settingsdeployer:assembleNormalRelease]
Task :org.settingsdeployer:preBuild UP-TO-DATE Task :org.settingsdeployer:preNormalReleaseBuild UP-TO-DATE Task :org.settingsdeployer:compileNormalReleaseAidl NO-SOURCE Task :org.settingsdeployer:compileNormalReleaseRenderscript UP-TO-DATE Task :org.settingsdeployer:checkNormalReleaseManifest UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseBuildConfig UP-TO-DATE Task :org.settingsdeployer:prepareLintJar UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseSources UP-TO-DATE Task :org.settingsdeployer:javaPreCompileNormalRelease UP-TO-DATE Task :org.settingsdeployer:mainApkListPersistenceNormalRelease Task :org.settingsdeployer:generateNormalReleaseResValues UP-TO-DATE Task :org.settingsdeployer:generateNormalReleaseResources UP-TO-DATE Task :org.settingsdeployer:mergeNormalReleaseResources FAILED
FAILURE: Build failed with an exception.
What went wrong: Could not resolve all files for configuration ':org.settingsdeployer:_internal_aapt2_binary'.
Could not find com.android.tools.build:aapt2:3.3.1-5013011. Searched in the following locations:
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
file:/C:/Users/Stuart/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011.pom
https://jcenter.bintray.com/com/android/tools/build/aapt2/3.3.1-5013011/aapt2-3.3.1-5013011-windows.jar Required by: project :org.settingsdeployer
Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I'm getting these errors when it tries to sync: ERROR: All flavors
must now belong to a named flavor dimension. Learn more at
https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Affected Modules: org.settingsdeployer
The flavor dimension problem is happened because you haven't add the flavorDimensions to your build.gradle. There must be at least one flavorDimensions. Something like this:
android {
...
defaultConfig {...}
buildTypes {
debug{...}
release{...}
}
// you need to specifies one flavor dimension.
flavorDimensions "version"
productFlavors {
normal {
// This property is optional if you are using only one dimension.
dimension "version"
applicationId "org.settingsdeployer"
versionCode 4
versionName "1.2"
}
french {
dimension "version"
applicationId "org.settingsdeployer"
versionCode 5
versionName "1.2_fr"
}
}
}
more details at Configure build variants
WARNING: Configuration 'compile' is obsolete and has been replaced
with 'implementation' and 'api'. It will be removed at the end of
2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Affected Modules: org.settingsdeployer
This warning is telling that we need to use either api or implementation to replace the compilation when adding dependencies. So, change the dependencies block to something like this;
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:21.0.3'
}

Error Android Studio:No dex files created while using Google's Calendar API

apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "com.example.calendarquickstart"
minSdkVersion 11
targetSdkVersion 24
versionCode 1
multiDexEnabled true
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
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:24.2.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'pub.devrel:easypermissions:0.1.5'
compile('com.google.api-client:google-api-client-android:1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-calendar:v3-rev210-1.22.0') {
exclude group: 'org.apache.httpcomponents'
}
}
I am trying to use google API for calendar but I am getting following error while running the app"
Information:Gradle tasks [:app:clean, :app:generateDebugSources,
:app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies,
:app:generateDebugAndroidTestSources, :app:assembleDebug]
Error:Execution failed for task
':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: No dex files
created at
C:\Users\user\AndroidStudioProjects\CalendarQuickstart\app\build\intermediates\transforms\dex\debug\folders\1000\10\guava-jdk5-17.0_bbc68f1b67df2c58337cd00757b7bfd105bb5573"
I am following the steps from this link
What changes need to be done in gradle file for running this app?
Try enabling the multidex support in your build.gradle file as stated in Configuring Your App for Multidex with Gradle:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Additional reading:
Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536—including Android framework methods, library methods, and methods in your own code. In the context of computer science, the term Kilo, K, denotes 1024 (or 2^10). Because 65,536 is equal to 64 X 1024, this limit is referred to as the '64K reference limit'.
Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.

Kotlin Android App compilation failed with message: Unresolved reference: kotlinx

I am testing out a basic Kotlin-based Android app based on the instructions in the "Kotlin for Android Developers" book. I am using Android Studio 2.1.1.
I have the following build.grade (Project: WeatherApp) setup:
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have the following build.grade (Module:App) setup:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
buildscript {
ext.support_version = '23.1.1'
ext.kotlin_version = '1.0.2'
ext.anko_version = '0.8.2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.qtimemedia.weatherapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'org.jetbrains.anko:anko-sdk23:0.8.3'
compile 'org.jetbrains.anko:anko-appcompat-v7:0.8.3'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
mavenCentral()
}
I have the following MainActivity.kt code:
package com.qtimemedia.weatherapp
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
message.text = "Hello Kotlin!"
}
}
Here is my activity_main.xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.qtimemedia.weatherapp.MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Here is my strings.xml code:
<resources>
<string name="app_name">WeatherApp</string>
<string name="hello_world">"Hello World!"</string>
</resources>
I am trying to run my MainActivity using the available Nexus 6 API 23 emulator. I have the option "Tools >> Android >> Enable ADB Integration" checked as on (I tried this with it off as well). The emulator appears to be working but my app does not appear to be loading due to a failed build. When running the emulator I see the following messages in the "4: Run" window:
C:\Users\Owner\AppData\Local\Android\sdk\tools\emulator.exe -netdelay none -netspeed full -avd Nexus_6_API_23
Warning: requested ram_size 1536M too big, reduced to 1024M
emulator: WARNING: Crash service did not start
emulator: WARNING: VM heap size set below hardware specified minimum of 384MB
emulator: WARNING: Setting VM heap size to 384MB
Hax is enabled
Hax ram_size 0x40000000
HAX is working and emulator runs in fast virt mode.
console on port 5554, ADB on port 5555
I see the following in the Event Log window:
11:26:05 PM Gradle sync started
11:26:15 PM Gradle sync completed
11:26:16 PM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
11:26:34 PM Gradle build finished in 18s 266ms
11:35:55 PM Executing tasks: [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
11:39:04 PM Gradle build finished with 3 error(s) in 3m 8s 551ms
I see the following in the Gradle Console window:
e: C:\Users\Owner\AndroidStudioProjects\WeatherApp\app\src\main\java\com\qtimemedia\weatherapp\MainActivity.kt: (5, 8): Unresolved reference: kotlinx
e: C:\Users\Owner\AndroidStudioProjects\WeatherApp\app\src\main\java\com\qtimemedia\weatherapp\MainActivity.kt: (12, 9): Unresolved reference: message
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
* 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: 3 mins 5.237 secs
In the Messages section I see the following:
C:\Users\Owner\AndroidStudioProjects\WeatherApp\app\src\main\java\com\qtimemedia\weatherapp\MainActivity.kt
Error:(5, 8) Unresolved reference: kotlinx
Error:(12, 9) Unresolved reference: message
Error:Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details
Information:BUILD FAILED
Information:Total time: 3 mins 5.237 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
How can I get the app to compile properly?
See the following response: https://stackoverflow.com/a/36526153/256513
You need to move the kotlin buildscript section from your project build.gradle to your module build.gradle file.
import the layout file from a R extension.
like this
import kotlindemo.app.com.myapplication.R.layout.activity_main;
import kotlinx.android.synthetic.main.activity_main.*

Android Studio :Null pointer exception when assembleDebugUnitTest gradle task is run

I am trying to run a simple JUNIT test for a test class in android studio. Build goes fine. When i try to run the JUNIT test i get the following error
*
Execution failed for task ':app:mockableAndroidJar'.
> java.lang.NullPointerException (no error message)
*
When i dumped the stacktrace i get the following. I am clueless as to why this is happening.
:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mockableAndroidJar'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteAc
tionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTa
skExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecu
tionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskEx
ecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecut
er.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptyS
ourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithN
oActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecut
er.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMost
OnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:31
0)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(Abst
ractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(Abst
ractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTask
PlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java
:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.ja
va:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:3
7)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:14
9)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessB
uildActionExecuter.java:90)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.
java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.
java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.
java:28)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSugges
tingBuildActionExecuter.java:50)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSugges
tingBuildActionExecuter.java:27)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineAct
ionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineAct
ionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.jav
a:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.jav
a:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFacto
ry.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFacto
ry.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.lang.NullPointerException
at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
at org.objectweb.asm.tree.ClassNode.accept(Unknown Source)
at com.android.builder.testing.MockableJarGenerator.rewriteClass(MockableJarGenerator.java:134
)
at com.android.builder.testing.MockableJarGenerator.createMockableJar(MockableJarGenerator.jav
a:91)
at com.android.build.gradle.internal.tasks.MockableAndroidJarTask.createMockableJar(MockableAn
droidJarTask.groovy:50)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAct
ion.doExecute(AnnotationProcessingTaskFactory.java:226)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAct
ion.execute(AnnotationProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAct
ion.execute(AnnotationProcessingTaskFactory.java:208)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:589)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:572)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteAct
ionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteAc
tionsTaskExecuter.java:61)
... 49 more
Test Environment used:
Environment: 1.2.2
SDK Version : API 21
Build tools 22.0.1
Android Plugin version : 1.2.3
Gradle version : 2.5
JDK : 1.7.0_79
Can you please help me out with this? Is there any problem with my setup?
Build Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.krishnaswamyna.testmathsapplication"
minSdkVersion 21
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.android.support:leanback-v17:22.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.31-beta'
testCompile 'org.robolectric:robolectric:3.0'
}
Jus delete the .gradle file in the project
I also had the same issue since a couple of weeks. I saw a hint about the issue being about the SDK from here.
What worked for me was to simply remove the SDK through the SDK Manager and then reinstalling it. You might also have to clean the project and/or invalidate cashes and restart Android Studio, between removing and reinstalling the SDK.
I had the same problem when i installed the Android Studio 2.0.
Uncheck Enable all test artifacts in:
File-> Settings-> Build, Execution, Deployement->Build Tools ->
Gradle-> Experimental gradle
Info: link
Clean the build and rebuild the app this might work and fix the issue. This gradle errors might come due to some old edited files just do the above said.

Run JUnit tests in Android studio

I created new Android Project and tried to run tests (JUnit) and had follow result:
15:28:53: Executing external tasks 'cleanTest test --tests com.binomv.rimidalv.tt.*'...
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'TT'.
Could not resolve all dependencies for configuration ':classpath'.
Artifact 'kxml2.jar (net.sf.kxml:kxml2:2.3.0)' not found.
Searched in the following locations:
https://jcenter.bintray.com/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar
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: 0.512 secs
Artifact 'kxml2.jar (net.sf.kxml:kxml2:2.3.0)' not found.
Searched in the following locations:
https://jcenter.bintray.com/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.jar
But if i use test through device - it is ok.
Thank you.
-----UPDATE-----
build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.binomv.rimidalv.tt"
minSdkVersion 14
targetSdkVersion 22
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.0.0'
compile 'com.android.support:support-v4:22.0.0'
}
----- SOLUTION -----
You should remove "~/.gradle" folder. Android Studio recreate it.

Resources