Posts

Showing posts with the label Gradle

Android Architecture Components: Gradle Sync Error For Dependency Version

Answer : As @RedBassett mentions Support libraries depends on this lightweight import (runtime library) as explained at android developers documentation. This is, android.arch.lifecycle:runtime:1.0.0 is spreading up in the dependency tree as a result of an internal api (transitive) import so in my case I only had to include extensions library as "api" instead of "implementation" so that it will override its version to the highest (1.1.1). In conclusion, change implementation "android.arch.lifecycle:extensions:1.1.1" to api "android.arch.lifecycle:extensions:1.1.1" In your main build.gradle file allprojects { ... configurations { all { resolutionStrategy { force "android.arch.lifecycle:runtime:1.1.1" } } } } This will enforce version 1.1.1 Apparently support-v4 was causing the conflict. In the case of this question, the Gradle dependency task wasn...

Android Resource Linking Failed

Answer : Please, provide some code. That will be very helpful. But, for now as the error shows: Daemon: AAPT2 aapt2-3.2.0-alpha17-4804415-windows Daemon #0 It means you must have some error in your XML files (layout files or drawable files), check your recent history of your XML file if you are working on Android Studio right click on xml file-> Local history-> show History or look for any error that XML file is showing. values.xml:352: error: resource android:attr/popupPromptView is private. And also refer to this error in values.xml file It happened to me twice, and both times it was an xml spelling error, and the error message was not very useful. The best way to identify a problem is to Analyze -> Inspect code -> search for clues in the "Syntax error" and find the xml with an error. I get this error while creating the legacy icons (Image asset) tool - I find that the Android studio does not close <Vector> tag in ic_launcher_...

Android Studio 3.2.1 - Cannot Sync Project With Gradle Files: Argument For @NotNull Parameter 'message' Of ... Must Not Be Null

Answer : Ok, I was finally able to figure out the reason. The problem was, that my project folder resided on a different hard disk partition, than my home folder. The folder containing my android projects was linked to my home folder with a symbolic link. I can't tell whether its the symbolic link, or the other partition, that is causing the problem. I haven't checked that. Maybe it works if you have it on the same partition but linked with a symbolic link. Maybe it works when used on another partition without symbolic links. But for anyone experiencing this problem -> Check if one of these might be your cause as well. Some extra information: My android project folder resided on a hard disk partition formatted with ZFS. I saw a version of this with just now on Android Studio 3.4: the only error message I saw in the IDE was that Gradle sync failed, but in idea.log there was a NullPointerException and its traceback originated at com.intellij.openapi.extensions.Exte...

BootJar + MavenJar. Artifact Wasn't Produced By This Build

Answer : As stated by gradle documentation here: Starting from Gradle 6.2, Gradle performs a sanity check before uploading, to make sure you don’t upload stale files (files produced by another build). This introduces a problem with Spring Boot applications which are uploaded using the components.java component More explanation is available in the link above. They propose the following workaround that I personally tried and worked for me : configure the outgoing configurations configurations { [apiElements, runtimeElements].each { it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) } it.outgoing.artifact(bootJar) } } here after the configuration from my build.gradle: .... apply plugin: 'maven-publish' ... configurations { [apiElements, runtimeElements].each { it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) } it.outgoing.a...

Android NDK With Google Test

Answer : If you choose cmake to drive your externalNativeBuild (and this is the preferred option, according to Android Developers NDK guide), then you can simply add the following lines to your CMakeLists.txt : set(GOOGLETEST_ROOT ${ANDROID_NDK}/sources/third_party/googletest/googletest) add_library(gtest STATIC ${GOOGLETEST_ROOT}/src/gtest_main.cc ${GOOGLETEST_ROOT}/src/gtest-all.cc) target_include_directories(gtest PRIVATE ${GOOGLETEST_ROOT}) target_include_directories(gtest PUBLIC ${GOOGLETEST_ROOT}/include) add_executable(footest src/main/jni/foo_unittest.cc) target_link_libraries(footest gtest) If your build succeeds, you will find app/.externalNativeBuild/cmake/debug/x86/footest . From here, you can follow the instructions in README.NDK to run it on emulator or device. Notes : make sure that the ABI matches the target you use (the guide is not very clear about this). the list of ABI's that are built is controlled by abiFilters in build.gradle . In Android ...

Android Studio Is Using This JDK Location ... Which Is Different To What Gradle Uses By Default

Answer : Update For macOS only happens on macOS Mojave 10.14.6 . On macOS Catalina 10.15.3 , you only need to set JAVA_HOME in your shell. This answer deals with macOS cases. It doesn't imply Linux or Windows solutions. TLDR On macOS , Android Studio doesn't receive your environment variables defined in your .bash_profile when launched from Finder.app . You must define your environment variables in launchctl : launchctl setenv JAVA_HOME /path/to/my/project/specific/jdk or, if you want to use your system-defined JDK: launchctl setenv JAVA_HOME `/usr/libexec/java_home` But this only works for the current session of your machine. Next, you have to create a ~/Library/LaunchAgents/environment.plist file: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label...

Android Studio ML Kit Cannot Load OCR Module

Answer : The solution was to update Google Play Services app. I did not consider this as an option at first as I would have expected an API 29 emulator to have an up-to-date Google Play Services installed. I signed into Google Play on the emulator, searched Google Play Services, uninstalled it (there was no "update" option), and installed it again. It still says that the installed version is 19.4.20 though the text recognition started working as expected. Here are some relevant logs: W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found. I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0 D/TextNativeHandle: Cannot load feature, fall back to load dynamite module. I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:1 I/DynamiteModule: Selected re...

Android Studio: How To Generate Signed Apk Using Gradle?

Answer : There are three ways to generate your build as per the buildType . (In your case, it's release but it can be named anything you want.) Go to Gradle Task in right panel of Android Studio and search for assembleRelease or assemble(#your_defined_buildtype) under Module Tasks Go to Build Variant in Left Panel and select the build from drop down Go to project root directory in File Explore and open cmd/terminal and run: Linux: ./gradlew assembleRelease or assemble(#your_defined_buildtype) Windows: gradlew assembleRelease or assemble(#your_defined_buildtype) If you want to do a release build (only), you can use Build > Generate Signed apk . For other build types, only the above three options are available. You can find the generated APK in your module/build directory having the build type name in it. It is possible to take any existing Android Studio gradle project and build/sign it from the command line without editing any files. This makes it very n...

Android Studio "No Tests Were Found"

Answer : Today I had the same problem with some Espresso tests and it was getting me crazy because everything seemed normal. Finally I discovered the problem was because the method annotated with @BeforeClass was throwing an exception. If something goes wrong in that method, the stacktrace of the exception is not shown in the Log window of the Run tab but in the Log window of the Android Monitor tab If you want to reproduce the problem just add this to your testing class: @BeforeClass public static void setupClass() { throw new RuntimeException("Sorry dude, you won't find any test!"); } This can happen when the type of your run configuration is incorrect. With me, this goes wrong when running an Espresso test which used to be a unit test. For some reason it still uses the Android JUnit test configuration when running this test. Manually creating an Android Instrumented Test solves the problem. Just for posterity sakes, here's the solution that worke...

Android Resource Compilation Failed In V3.2

Answer : I was facing this issue today after updating gradle from 3.1.4 to 3.2.0 . I don't know why, but the build started to throw that exception. i deleted the build folder, and deleted the gradle caches folder but nothing worked, so i looked at the merged values.xml and turns out that my ids.xml was defining a wrong id that was being merged to the values.xml : <?xml version="1.0" encoding="utf-8"?> <resources> <item name="downloading_package" type="id">Baixando pacote de sincronização</item> </resources> And apparently this was working before the update... for my case i deleted the ids.xml file (it was useless in the project) I wish i could know why before the update everything was working the <item> in values.xml at line 900 ...might be of resource-type id . the correct syntax would be (just as the error message tells): <?xml version="1.0" encoding="utf-8...

Cannot Install Support Repository And Sync Project In Android Studio

Answer : Previously the Android Support Library dependencies were downloaded from Android SDK Manager. Now all the new versions are available from Google's Maven repository. In future all android libraries will be distributed through maven.google.com So, by adding the below code to the repositories will build the project. repositories { maven { url "https://maven.google.com" } } I had to add the following to my project level build.gradle. Then the button to install and worked. allprojects { repositories { maven { url "https://maven.google.com" } jcenter() } } Try using the latest support library versions: compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.google.android.gms:play-services-vision:10.2.1' compile 'com.android.volley:volley:1.0.0' //...

Android Studio How To Run Gradle Sync Manually?

Image
Answer : Android studio should have this button in the toolbar marked "Sync project with Gradle Files" EDIT: I don't know when it was changed but it now looks like this: EDIT: This is what it looks like on 3.3.1 OR by going to File -> Sync Project with Gradle Files from the menubar. WARNING : --recompile-scripts command has been deprecated since gradle 's version 5.0. To check your gradle version, run gradle -v . ./gradlew --recompile-scripts it will do a sync without building anything. Alternatively, with command line in your root project ./gradlew build It will sync and build your app, and take longer than just a Gradle sync To see all available gradle task, use ./gradlew tasks In Android Studio 3.3 it is here: According to the answer https://stackoverflow.com/a/49576954/2914140 in Android Studio 3.1 it is here: This command is moved to File > Sync Project with Gradle Files .

Android Studio Run/Debug Configuration Error: Module Not Specified

Answer : Resync your project gradle files to add the app module through Gradle In the root folder of your project, open the settings.gradle file for editing. Cut line include ':app' from the file. On Android Studio, click on the File Menu, and select Sync Project with Gradle files . After synchronisation, paste back line include ':app' to the settings.gradle file. Re-run Sync Project with Gradle files again. never mind, i changed the name in settings.gradle and synced and then changed it back and synced again and it inexplicably worked this time. Try to delete the app.iml in your project directory and restart android studio