Cannot convert the provided notation to a File or URI - android

I am getting the following error when running espresso test ./gradlew connectedAndroidTest
> Task :app:fixStackFramesLiveDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:fixStackFramesLiveDebugAndroidTest'.
> Cannot convert the provided notation to a File or URI: classes.jar (androidx.databinding:databinding-adapters:3.4.1).
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
app/build.gradle contains the following
...
android {
.....
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...
}
dataBinding {
enabled = true
}
}
...
Irrespective of espresso dependencies, I am getting the above error. Can someone please help to resolve this issue. I am new to android and espresso.
I am not sure if I had missed out information. Please let know if needed.

On Android Studio 4.0 canary 4 with Gradle Kotlin DSL enabled, I got the kinda same error:
Unable to resolve dependency for ':app#debug/compileClasspath': Cannot convert the provided notation to a File or URI: {dir=libs, include=[*.jar]}.
After I changed my build script from
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}
to
dependencies {
implementation(fileTree(Pair("dir", "libs"), Pair("include", listOf("*.jar"))))
}
everything works well. WTF.

I ran into this error after updating gradle to 3.4.+ After I downgraded to 3.3.2 I was able to build without any issues.

Related

Build with R8 failing -> Error: Multiple annotations of type `dalvik.annotation.EnclosingClass`

I am getting the error on building the project from command line:
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:118)
at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:102)
at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:444)
... 22 more
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.t.a(:55)
at com.android.tools.r8.D8.run(:11)
at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:116)
... 24 more
Caused by: com.android.tools.r8.utils.AbortException: Error: Multiple annotations of type `dalvik.annotation.EnclosingClass`
at com.android.tools.r8.utils.Reporter.a(:21)
at com.android.tools.r8.utils.Reporter.a(:7)
at com.android.tools.r8.utils.t.a(:36)
... 26 more
Android Studio Version: 3.5
Gradle Plugin: 3.5.1
Gradle: 5.4.1
(I can't add a comment, which requires 50 reputations, huh.)
As mentioned by sgjesse#, using the latest R8 will show from which such a class file with invalid attributes came. For example, https://issuetracker.google.com/issues/142002569#comment4 like:
AGPBI: {"kind":"error","text":"A member class should be a (non-member) local class at the same time.\nThis is likely due to invalid EnclosingMethod and InnerClasses attributes:\n[enclosingClass: Lcom/tealium/library/c;, enclosingMethod: null]\n[access : 18, inner: Lcom/tealium/library/c$a;, outer: Lcom/tealium/library/b;, innerName: a]\n","sources":[{"file":"/Users/dps.developer/Documents/XXX_Repos/flagshipapp/libs/tealium.4.1.4c.jar"}],"tool":"R8"}
In addition to attributes you mentioned, it would mention which class file or jar includes that class file. Then, it would need to be fixed in one of the involved compilers responsible for that jar file. Could you let us know the full error message, including "sources" of invalid attributes?
This could be caused by invalid input. Please take a look at https://issuetracker.google.com/142002569#comment2, and try using a newer R8 version which will provide more info in this case (the latest version is 1.6.36 now).
You can try the 3.6 release (without upgrading gradle plugin) by adding the following to your top level build.gradle file:
buildscript {
repositories {
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:1.6.36' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP (3.5.1 in this case) version.
}
}
use android.enableSeparateAnnotationProcessing=true in gradle.properties worked for me .

Some file crunching failed, mergeDebugResources FAILED

This error occurred today after I updated Android Studio from 2.2 to 2.3 , and run app to my phone. Everything was OK last Friday. This Monday gift ruined my all day.
Gradle setting is "Use local gradle distribution", version 3.3 .
log info as below, because it's too long and all of them are similar, I just copied some segments:
Error: Some file crunching failed, see logs for details
:app:mergeDebugResources FAILED
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-mdpi-v4\abc_btn_switch_to_on_mtrl_00012.9.png ERROR: Unable to open PNG file
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-xxhdpi-v4\abc_ic_star_half_black_48dp.png ERROR: Unable to open PNG file
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-hdpi-v4\abc_ic_menu_share_mtrl_alpha.png ERROR: Unable to open PNG file
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-xxhdpi-v4\abc_text_select_handle_middle_mtrl_light.png ERROR: Unable to open PNG file
AAPT err(Facade for 925134644) : No Delegate set : lost message:\\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-hdpi-v4\abc_ic_star_half_black_48dp.png ERROR: Unable to open PNG file
AAPT err(Facade for 925134644) : No Delegate set : lost message:\\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-mdpi-v4\abc_switch_track_mtrl_alpha.9.png ERROR: Unable to open PNG file
build.gradle as below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
aaptOptions {
cruncherEnabled = false
}
defaultConfig {
minSdkVersion 18
targetSdkVersion 18
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
useLibrary 'org.apache.http.legacy'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.jetbrains:annotations-java5:15.0'
}
}
According to advice from other questions, although some answers are just too outdated, still I have tried following ways, unfortunately, none of them saved me:
1. remove all .9.png files from my project.
2. check all png files are real PNG.
3. insert following settings to build.gradle :
aaptOptions {
cruncherEnabled = false
}
4. check project file path, not reaching 255 characters (Windows 10).
5. clear gradle caches.
6. Invalidate caches and restart.
7. clean project.
I think log info leads me to files auto-generated by Android Studio. Trying to search error .png files, none of them exists in my project.
Any advice is appreciated.
problem solved. The solution is here.
Related data as below:
1. According to release notes of Android Studio version 2.3, build cache is enabled by default.
2. so we should disable this setting. Here is official guide, Android Studio/User Guide/build-cache(link https://developer.android.com/studio/build/build-cache.html).
3. go to gradle.properties file, and disable build cache.
// To re-enable the build cache, either delete the following
// line or set the property to 'true'.
android.enableBuildCache=false
the other way is to modify build cache dir by adding
# first line can be skipped because true is the default value by 2.3
android.enableBuildCache=true
android.buildCacheDir =c:\\temp\\
It's causing this error because in your drawable you must have change the extension to .png from other format.I would recommend that to change the extension use MS paint or Other image editing application like Gimp.

when I start test apps from genymotion , I got error

(Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
java.lang.RuntimeException: Exception while checking library jar)
Please can anybody help me.
This error is generally showed, when you have duplicate dependencies with different versions.
Check your dependencies thoroughly.
you can also use following command:
gradle dependencies
and if your dependencies are in order try adding following in build.gradle file
defaultConfig {
multiDexEnabled true
}

Android studio with experimental gradle 0.2.0

I am trying to setup a basic ndk build with the latest version of android studio at this moment. Trying to follow this tutorial
This is my gradle-wrapper.properties
#Thu Sep 17 14:22:34 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip
This is the project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is my module's build.gradle
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "me.blubee.testnative_exp"
minSdkVersion = 10
targetSdkVersion = 23
versionCode = 1
versionName = "1.0"
}
buildConfigFields.with {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
create("flavor1") {
applicationId = 'com.app'
}
}
android.sources {
main {
java {
source {
srcDir 'src'
}
}
}
}
}
}
my project structure looks like this:
APP
Java/
Java/android.support
Java/com.test.test_experimental
Java/com.test.test_experimental/R
Java/com.test.test_experimental
Java/com.test.test_experimentalBuildConfig
Java/com.test.test_experimental
Java/com.test.test_experimental/MainActivity
tests/
tests/com.test.test_experimental
tests/com.test.test_experimental/ApplicationTest.java
tests/com.test.test_experimental
tests/com.test.test_experimental/BuildConfig.java
resources/
test-resources
gradle/scripts/
I am getting these errors:
2:51:31 PM Gradle sync started
2:51:34 PM Gradle sync failed: Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Consult IDE log for more details (Help | Show Log)
Error:Unable to load class 'com.android.build.gradle.managed.ProductFlavor_Impl'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
Brother:TestNative_exp blubee$ ./gradlew clean --stacktrack
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/bb/TestNative_exp/app/build.gradle' line: 10
* What went wrong:
A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> Cannot set readonly property: minSdkVersion for class: com.android.build.gradle.managed.ProductFlavor_Impl
* 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: 2.619 secs
line #10 is: minSdkVersion = 10
You can see the whole file in the build.gradle that i put above.
edit
As #unbekant pointed out in his comment and the link to this post
The min and target sdk values should be set like this:
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 22
I tried that as well, I get this error:
* What went wrong:
A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: model.android
> No such property: buildConfigFields for class: com.android.build.gradle.managed.AndroidConfig
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
What am I doing wrong?
You have to put these blocks outside the android block.
android.buildTypes
android.sources
android.productFlavors
Also the buildConfigFields.with should be inside the defaultConfig or inside the buildTypes or productFlavors:
Something like:
model {
android {
compileSdkVersion = 22
buildToolsVersion = "22.0.1"
defaultConfig.with {
//----
minSdkVersion.apiLevel = 10
targetSdkVersion.apiLevel = 23
buildConfigFields.with {
create() {
//....
}
}
}
}
android.buildTypes {
release {
//
}
}
android.productFlavors {
//
}
// Configures source set directory.
android.sources {
//
}
}
Also, the last version is 0.2.1.
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
There's a tutorial? Oh, that. Where are the links?
The current version is 0.2.0.
or dates?
I googled every one of the missing files individually (maybe 3 dozen!) after adding:
classpath 'com.android.tools.build:gradle-experimental:0.2.1'
I tried the alpha version too but I failed finding some of its dependencies altogether.
First I get a couple of dependencies I can be bothered chasing down:
> Error:Could not find com.android.tools.build:gradle-experimental:0.2.1.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle-experimental/0.2.1/gradle-experimental-0.2.1.jar
Once each of these was added to the given path seven more would sprout up in its place. If someone could post how to automatically update these (they still aren't in the latest 1.4RC1 Android Studio) it would be very useful. I got most of the stuff from maven, eg http://mvnrepository.com/artifact/com.android.tools.lint/lint-checks/24.3.1
I got all the files to shut up Gradle's whining and you know what it said?
Error:(34, 1) A problem occurred evaluating project ':app'.
> Error: NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Set "android.useDeprecatedNdk=true" in gradle.properties to continue using the current NDK integration.
Which was exactly the error that led me to migrate to experimental and no better than the stock 1.3.0 that ships with AS (though it was defaulting to 1.2.3).
Why did I bother? I want to debug NDK and couldn't see what else I wasn't doing apart from not using an experimental build.
This goose chase was just a big waste of time. I'm back to using
android.useDeprecatedNdk=true
No doubt I can fix it somewhere else but just a warning to others chasing experimental dependencies; they are unicorns.
#jonagon
Some examples are in this repo:
https://github.com/googlesamples/android-ndk
probably could try:
Use the latest plugin version. Find it at:https://jcenter.bintray.com/com/android/tools/build/gradle-experimental
check https://github.com/googlesamples/android-ndk/blob/master/hello-jni/app/build.gradle for product flavors
jni folder issue:
it is default for gradle experimental plugin, also for older c++ support NOT using gradle-experimental plugin ( android plugin )
if you have that folder and not using experimental plugin, Gradle thinks that app is using the older android studio c++ support. It gives your that warning "NDK integration is deprecated in the current plugin" and recommend you to experimental plugin. it could be silenced with:
sourceSets.main.jni.srcDirs = []
or just rename that jni folder to something else: it will cause more trouble if you want to android-studio cmake/ndk-build in the future, rename is better.

Gradle - Unexpected top-level exception - Out of nowhere

Fairly certain gradle is out for me. Started a project that has been working fine just a few days ago. Updated android studio and opened the project again. I have tried everything I can come up with, from removing/updating libraries checking xml-files and structure. Removing gradle cache and installing latest jdk, nothing seems to help here.
Also tried to add:
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
Refered in other posts on stackoverflow
I exported the error from the console, and it looks like this:
objc[2338]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
:Derp:dexDerpDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':Derp:dexDerpDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/19.1.0/dx --dex --num-threads=4
--output /Users/MorePathStuffForALongWhile
Error Code:
2
Output:
objc[2338]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
Your problem: You've passed the approx. 65000 method limit when compiling the app. You must find a way to reduce the number of methods in your app.
In the case that you are using Google Play Services, you can try this method to compile it with more granularity.
If not, you can simply use multiDex (make sure that you are using a recent version of Android Studio). Use this in your build.gradle file:
android {
defaultConfig {
...
multiDexEnabled = true
}
}
If you using gson or jackson, try removing its dependencies. It worked for me.
compile 'com.google.code.gson:gson:2.1
Your source code + all included libraries end up with more than 65k method definitions. This is currently a limitation of dex.
In order to avoid this situation, multidex support was introduced. A compile time the output classes are split and bundled in multiple dex files. And at runtime they are loaded from multiple dex files.
To achieve this you need to add multidex support:
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'
}
And set an Application class extending MultiDexApplication.

Categories

Resources