Android Studio Build/Clean - android

In an attempt to compile external jars, I have to use the terminal and do a clean. However, when I go into the root directory of my project and execute
gradlew clean
I get the following message:
-bash: gradlew: command not found
Here's a screenshot of my application folder's home directory.
Let me know if you need anything else, I'm not sure why this is happening.

gradlew is not in your global path. To execute the 'clean' task (or any task for that matter) using the gradle wrapper (gradlew) in your project directory in your terminal, specify the current directory with the './':
./gradlew clean

You need to give it the permission by running this one first:
chmod 777 gradlew

gradlew is not in your global path. To execute the 'rebuild' task (or any task for that matter) using the gradle wrapper (gradlew) in your project directory in your terminal, specify the current directory with the './':
./gradlew rebuild

Related

Delete downloaded robolectric jars

I am writing a Gradle task around Robolectric in Android Studio. How can I delete the jars that it downloads at runtime? I need a clean slate to test my task.
I tried running clean but that didn't cause the jar to be redownloaded on next run.
Is there a command I can run? Or where can I find the directory for downloaded jars?
I could not find a designated clean command, but I found a workaround:
Run test with debug flag -d; can be set either in Preferences>Compiler>Command-line Options, or run from terminal with ./gradlew :app:testDebugUnitTest -d --tests com.package.YourTestClass.testMethod > gradle_log.txt 2>&1
In the logs, search for this: Dependency cache location:
The destination directory be specified on that line. Then you can just remove it rm -r /var/folders/directoryname

Error: Could not initialize class com.android.build.gradle.internal.crash.PluginCrashReporter

We created a ionic app with angular. When we use
ionic serve
Then its working fine.
But when we are generating android apk then we are getting this error:-
* Where:
Build file '/home/ankur/projects/ionicdesign/ionic-roots_v101/ionic
apps/kisansanchar/medical/platforms/android/app/build.gradle' line: 20
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not initialize class com.android.build.gradle.internal.crash.PluginCrashReporter
Here is complete log details:-
Paste Bin
Any idea about this error?
I've had the same issue.
Digging into gradle command with --scan, I've found the problem.
My ~/.android was owned by root, so my build (launch by my user) failed to read/write into this directory.
Solution: sudo chown -R you:you ~/.android
For me, it was the kotlin_version in build.gradle, the one used for building is lower than what was configured for my IDE, so what I did is deleted my .gradle caches by typing this in terminal rm -rf $HOME/.gradle/caches/
Then restarted my project in my case it was a flutter project so flutter run is the command. everything is taken care of after that.

Gradle task assembleRelease not found in CI build, works with Android Studio

I am trying to use gitlab/fastlane to build my project.
When i execute the scripts in the default project they work correctly, but when the runner checks out the project the build fails with the message "Task 'assembleRelease' not found in root project 'projectname'".
When i open the CI project location in Android Studio I have to execute "sync project with gradle files" before build is available.
After I have done this i can execute ./gradlew assembleRelease (and the fastlane script also works correctly)
The console output shows that several files/directories are removed when the repository is checked out:
Removing .gradle/
Removing .idea/
Removing app/app.iml
Removing app/build/
Removing build/
Removing local.properties
Removing project.iml
I can't seem to find what exactly Android Studio does when I select "Sync Project with Gradle Files" and how i reproduce that with my build script.
I had the same problem. The reason was that the ANDROID_HOME environment variable was not set and the local.properties file did not have an sdk.path set.
You could set it via Jenkinsfile into the local.properties file:
sh 'echo "sdk.dir=/<your_path_to_Android_SDK>" > ./local.properties'
in my case:
sh 'echo "sdk.dir=/home/jenkins/Android/Sdk" > ./local.properties'
Instead of writing it into the Jenkinsfile you could also create a custom fastlane lane which calls the the above mentioned shell command before you execute ./gradlew assembleRelease

Gradle not finding updated NDK path & project directory

I moved my Android SDK (and NDK) when my hard drive failed.
In my working project, I updated local.properties to reflect these changes in the variables ndk.dir and sdk.dir, yet when I run ./gradlew clean --info on the command line from within my project directory, gradle gives me a failure at the following command:
<old_ndk_path>/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=<oldprojdir>/app/src/main/jni/Android.mk APP_ABI=armeabi NDK_ALL_ABIS=armeabi NDK_DEBUG=1 APP_PLATFORM=android-23 NDK_OUT=<oldprojdir>/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=<oldprojdir>/app/build/intermediates/ndkBuild/debug/lib clean
It's no wonder that the task fails, since no executable exists at that path now, but how can I get gradle to make use of the new NDK path? And how can I make it use the new project directory?
Delete the <projdir>/.gradle directory and try again.

Android project and Gradle: assemble a single module

I have an Android Studio project that contains several sub-projects (aka: modules).
I would like to build some of these sub-projects from the command line.
I read on the Android dev guide that you can build your project by simply running
gradlew.bat assembleDebug
from the command line, however this always builds the entire project (all the modules)
I just want to assemble a single module, how do I do that?
Another way to do this is:
gradlew.bat :myModule:assembleDebug
https://stackoverflow.com/a/16987319/1807627
gradlew.bat assembleDebug -a -b path/to/module/build.gradle
-a only builds the component and does not rebuild its dependencies
Use -b to specify another Gradle build file. In this case, the module's instead of the top-level build.gradle.
If you weren't using the Gradle wrapper, you could alternatively just cd to the module directory and run gradle assembleDebug -a there.

Categories

Resources