Gradle cannot find the AndroidSDK path on Windows - android

I am just setting up a gradle build for a android project on a windows machine, after it has worked well on a mac. I have defined a local.properties file like so:
sdk.dir="C:\Program Files\android\sdk"
When attempting to use gradlew.bat I see the following:
C:\Users\PeterNied>gradlew
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\PeterNied\build.gradle' line: 9
* What went wrong:
A problem occurred evaluating project ':MyProject'.
> The SDK directory 'C:\Users\PeterNied\"C:Program Filesandroidsdk"' does not exist.
* 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.224 secs
Clearly the computation of the android sdk directory is just combining the local directory and the destination that I specified C:\Users\PeterNied\"C:Program Filesandroidsdk". How do I point gradle to the right place?

Just using
sdk.dir=C:/Program Files/android/sdk
should work (in general, replacing backslashes by forward slashes).
The path separator and path concatenation are just the same issue.

There are two aspects of this problem, the path seperator, and dealting with the gradle local.dir + sdk.dir concatination:
You can swap the '\' -> '/' in order to prevent the the path seperators from getting lost
I've been unable to 'define' a root path for gradle to use instead, so I'm going to work around this problem by creating a path that will resolve to the right location like the following:
sdk.dir=../../Program Files/android/sdk
Its a little ugly, but it will get you building.

Related

Could not find method google() for arguments [] on repository container. (flutter)

cmd > flutter run
Launching lib\main.dart on Lenovo A6020a40 in debug mode...
Initializing gradle... 1.8s
Resolving dependencies...
* Error running Gradle:
ProcessException: Process "C:\Users\Mantu Kumbhakar\Downloads\sytody-master\android\gradlew.bat" exited abnormally:
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\Mantu
Kumbhakar\AppData\Local\Android\sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
BUILD FAILED
Total time: 3.065 secs
Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
FAILURE: Build failed with an exception.
Where:
Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 27
What went wrong:
A problem occurred evaluating script.
Could not find method google() for arguments [] on repository container.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Command: C:\Users\Mantu Kumbhakar\Downloads\sytody-master\android\gradlew.bat app:properties
This error is sometimes generated when you try to run a project created using an older version of Flutter than the one you're currently using.
The issue can also be found on the Flutter GitHub repository.
Until an official solution to this issue is provided, you can fix it by recreating the project with your newer version of Flutter, as suggested in the above GitHub issue too.
Above, when Abhijeet said: "This error is sometimes generated when you try to run a project created using an older version of Flutter than the one you're currently using." is correct.
Causes
When a project is created with flutter create foo several files in the ios/ and android/ sub-directories are created.
Newer Flutter versions might generate these files a bit differently and projects created with older Flutter versions might cause issues.
to fix:
Supposing that your project is in c:\root_of_your_project\name_of_your_project
Delete the ios/ and android/ directories and go to root directory of your project with CMD, and:
c:\root_of_your_project\flutter create -a kotlin name_of_your_project
and
c:\root_of_your_project\flutter create -i swift name_of_your_project

SDK Location not Found In Gradle Command Line Linux

I am trying to build my project using fdroid but it keeps failing when it gets to gradle. The project builds well in android studio but it always fail in gradle command line. I have search google multiple times but i could not get help from any website. I have set my ANDROID_HOME to /home/collins/Android/Sdk but it seems gradle ignores the variable, Each time i try to build, i noticed that gradle generates a local.properties file with the wrong sdk location value:
sdk.dir=$ANDROID_HOME
sdk-location=$ANDROID_HOME
I don't know if there is a way to set the global default value for any project in gradle. Here is the full log from fdroid build
INFO: Building version 3.0 (3) of com.simpledecredwidget
INFO: Getting source for revision 0ca18981c4b3825861b07e1f2444f711fc8a4fa5
INFO: Creating local.properties file at build/com.simpledecredwidget/local.properties
INFO: Creating local.properties file at build/com.simpledecredwidget/app/local.properties
INFO: Cleaning Gradle project...
ERROR: Could not build app com.simpledecredwidget: Error cleaning com.simpledecredwidget:3.0
==== detail begin ====
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 /home/collins/Documents/Projects/fdroiddata/build/com.simpledecredwidget/app/$ANDROID_NDK.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '/home/collins/Documents/Projects/fdroiddata/build/com.simpledecredwidget/$ANDROID_HOME' does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
==== detail end ====
INFO: Build for app com.simpledecredwidget failed:
Error cleaning com.simpledecredwidget:3.0
==== detail begin ====
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 /home/collins/Documents/Projects/fdroiddata/build/com.simpledecredwidget/app/$ANDROID_NDK.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '/home/collins/Documents/Projects/fdroiddata/build/com.simpledecredwidget/$ANDROID_HOME' does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
==== detail end ====
INFO: Finished.
INFO: 1 builds failed
EDIT
As you can see in the error above, The sdk location /home/collins/Documents/Projects/fdroiddata/build/com.simpledecredwidget/$ANDROID_HOME was used which was incorrect, i don't know where this bug is coming because a different value was set in local.properties file which value is sdk.dir=$ANDROID_HOME

Failed to find target with hash string 'android-25' in: /home/hisham/Android/Sdk

Been trying to debug this issue for hours! Tried many solutions online, none seems to be working.
Build properties not found for package Android SDK Platform 25
File /root/.android/repositories.cfg could not be loaded.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
>
Failed to find target with hash string 'android-25' in: /home/hisham/Android/Sdk
* 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: 39.749 secs
Error: /home/hisham/Desktop/Dev-PGDoc/ionic_app/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'android'.
> Failed to find target with hash string 'android-25' in: /home/hisham/Android/Sdk
How do I fix this?
Finally got it fixed! Not sure which one of the following fixed it though.
Change $ANDROID_HOME inside ~/.bashrc from ANDROID_HOME=$HOME/Android/Sdk to ANDROID_HOME=$HOME/Android/Sdk/platform-tools
Deleted version 25's folder inside platform-tools folder in the Sdk and installed version 25 again.
After doing the two above, restarted the system and I am now able to compile and build ionic app to .apk files.
PS : This might be just only in my personal computer, and you might be facing the same issue due to different issue. Hope this helps.

react native run android in emulator throws erro

i install react native and open a new project.
i try to run
react-native run-android
and I get this error
PS E:\Projects\React native\myapp> react-native run-android
Scanning 574 folders for symlinks in E:\Projects\React native\myapp\node_modules (27ms)
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
FAILURE: Build failed with an exception.
* Where:
Build file 'E:\⌠°σΘΘ≈ΦΘφ\⌠°σΘΘ≈ΦΘφ ≈Θ⌡\React native\myapp\android\app\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Your project path contains non-ASCII characters. This will most likely cause the build to fail on Windows. Please move your project to a different directory. See http://b.android.com/95744 for details. This warning can be disabled by adding the line 'android.overridePathCheck=true' to gradle.properties file in the project directory.
* 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.877 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
As you can see from the error you need to move your project to a different directory with no non-ASCII characters.
Your project path contains non-ASCII characters. This will most
likely cause the build to fail on Windows. Please move your project
to a different directory. See http://b.android.com/95744 for details

How to clear Gradle scripts cache folder automatically?

Welcome all
I'm developing an automatic APK generator which compiles android apps using gradle console commands. I found this problem:
FAILURE: Build failed with an exception.
* What went wrong:
Failed to create parent directory '/root/.gradle/caches/2.2.1/scripts/settings_14c7jxprvkvxiv2ted70j3e0u' when creating directory '/root/.gradle/caches/2.2.1/scripts/settings_14c7jxprvkvxiv2ted70j3e0u/SettingsScript/buildscript'
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
java.lang.Exception: Error processing Build command. Error code: 1
The problem is that directory /root/.gradle/caches/2.2.1/scripts/has hundreds of thousans of subdirectories generated and it has reached linux inode limit.
Why is gradle generating all those directories and how can i tell gradle to stop this? Whould be perfect if gradle has an option to delete/clean these cache directories automatically.
IMPORTANT: I'm not using android studio, all the process is automatized and using console commands (gradle assembleRelease)
Thx

Categories

Resources