$PATH not set properly when running Gradle from IntelliJ/Android Studio - android

I have an Android project which includes a JavaScript app. The JS app uses Yarn for package installation and running the build script. When building from the terminal with the Gradle Wrapper everything works fine. But when I try to build/run the project from IntelliJ/Android Studio all environment variables I have set for my account (including $PATH) are reset. It seems like the Gradle runner in IntelliJ and Android Studio executes the build in an isolated shell. Since $PATH is not properly set up, it doesn't find Yarn and Node to build the JavaScript app.
I've searched through all settings in IntelliJ and Android Studio and couldn't find anything related to environment configuration for Gradle. Did anyone else have this issue?
Opening up a terminal in IntelliJ itself and running Gradle from there works properly.
I'm working on macOS Sierra with IntelliJ 2017.3 and Android Studio 3.0.1. The only reason I'm using both is that after not working in Android Studio I thought it might run in IntelliJ.

It seemed to be a bug in Android Studio. I needed to set at least one environment variable in Android Studio itself and then it suddenly also picked up all existing env properties.

For me it got solved when I updated Android studio from 3.0.1 to version 3.1.3.

Related

ionic cannot run app in android studio missing config and showing unresolved libraries

i'm using ionic and i try to run my app in android studio. On Ios everything is working fine but android studio is always saying please add configuration. I actually have no idea how to add a configuration. Also my project contains three packages. I'm building my project with the following commands:
ionic build
npx cap sync
npx cap open android
Also android studio cannot resolve some libraries.
Please find attached a screenshot of the errors i have mentioned above:
thank you
I had this same issue, and I think it was a few problems compounded. It looks like you shouldn't have to add configurations manually, so if the "app" configuration doesn't appear automatically then something is wrong. I ran
ionic cap build android
which built everything and launched android studio. If that doesn't fix it, you might be missing some sdks. Try running this command from your android folder.
./gradlew assembleDebug
Mine complained about missing a specific version of the android sdk which I had to install with the android studio sdk manager. Then I relaunched android studio, and the "app" configuration was there.

Android Studio running Android (Java) Project as Flutter Project

Situation and Problem
I have been working with Android Projects using android studio for a while in Java. Recently, I have started learning Flutter and therefore added Flutter modules into Android Studio.
I opened both Android Project and Flutter Project at the same time in different windows and both project can share the same emulator, and everything seemed to work fine. Yet, the next day I opened the Android Project again, the WHOLE IDE was configured with Flutter settings. This means that:
1. Android Project is NOT synced with gradle, and thus all the imports failed marked red
2. All gradle related files are not visible in the project folder in Android Studio (still exists in folder)
3. All gradle operations are gone because the IDE is configured for Flutter. So there is no rebuild project/clean project/ sync with gradle files button
Things I have tried
Reopen the project
Invalidate cache and restart
Restart PC
But none of them seemed to work. If I tried to create a new Android Project, the new Android Project seems to work fine with all gradle operations available.
Android Studio Versions
Android Studio 3.4
JRE: 1.8.0_152-release-1343-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
I tried to look for similar issues but none seems to match this one. Any one can help?
I had a similar issue. Yesterday, I updated Android Studio to 3.6.1 and that fixed it. Try that.
I found the workaround solution is to import the project again instead of opening the project.
When importing, remember to choose opening it as an Android Gradle Project.

Gradle version to use with Android/Cordova CLI

I currently use Cordova CLI on Windows to build hybrid Android apps. I am in the process of moving my development mover to a headless Ubuntu server. Getting java, NVM, Node, Android SDK and Cordova CLI installed on Ubuntu has not been a problem. Having done so and created the customary Cordova hello world project,
cordova create hello com.example.hello HelloWorld
I proceeded to add the Android platform
cordova plaform add android
and then attempted to build
cordova build android
at which point I was told
Error: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
Installing Gradle by following the instructions given here - I am NOT installing Android Studio and am working on a headless Ubuntu machine so automatic Gradle installation is not an option - is not a problem. However, it is not clear to me which version of Gradle I should install.
I do not want to break my current Cordova project so I am trying to replicate the current Windows/Cordova CLI setup as closely as I can
Node 8.9.2
Java 8
Gradle ???
Dipping inside the gradle-wrapper.properties file in my existing project I find
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
I have noted that when I compile the project at present there are some ominous warnings about features to be removed from future versions of Gradle that are shown. I could experiment with using gradle-2.10 but it is not entirely clearr to me that it would indeed be the right version. Hopefully, someone here will be able to point me in the right direction.
First, clean up the project
cordova clean android
Then, force the cordova to use the distribution url with the version you want, in this case: gradle-6.3
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\\://services.gradle.org/distributions/gradle-6.3-all.zip
Then, build your application.
cordova build android --release

Can't get Terminal Emulator for Android to build in Android Studio

I'm trying to build Terminal Emulator for Android. I'm running Android Studio 1.4 in Kubuntu 15.04. I also tried building it in Ubuntu 14.04 LTS with the same results. The project requires the latest Android NDK, SDK 22, and SDK 11 which I've downloaded and configured in Android Studio. My system gradle version is 2.8, and Android Studio has downloaded some other versions internally. I'm using jdk1.8.0_65, which is set to JAVA_HOME and configured in Android Studio. I've built several other projects with my configured Android Studio and only seem to have a problem with this project. I need to use this project as a base for an app I'm developing.
I end up with same error, posted below, no matter what route I take to fix it in Android Studio. This is generally what I've done to try and get the project to work. I open up the project unmodified in Android Studio. I click Build >> Rebuild Project. I get an error telling me ndk implementation is deprecated. I add a file gradle.properties to the root directory of the project with the line android.useDeprecatedNdk=true and rebuild. It gives me an error: Task 'generateDebugTestSources' not found in project. I execute Sync Project With Gradle Files to resolve it. Then I end up with the following error and can't get past it.
Gradle 'Android-Terminal-Emulator-master' project refresh failed
Error:exception during working with external system:
or
Gradle sync failed: exception during working with external system:
Consult IDE log for more details (Help | Show Log)
idea.log
Things I've done to try and get the project to build:
Modify all of the project's build.gradle files to use the experimental plugin
Use different versions of Android Studio
Switch from openjdk to Oracle's jdk
Upgrade gradle to the latest version
Set gradle to default wrapper (default) and also set gradle to different versions
invalidate cache, remove ~/.gradle, and rebuild project
Make sure PATH includes the gradle and jdk bin directories and is in ~/.bashrc, ~/.profile, and ~/.zshrc
remove proguard from libtermexec library
reboot computer
I should note that the project builds without issue on the command line. I'd really like to get the project to build in Android Studio for development.
Install Arch and run Android Studio there.
I decided to try building Terminal Emulator on my Arch server, so I installed a xfce (Desktop Environment) and Android-Studio through pacman. I followed the same general path to get things setup, and the app built without issue.
The idea log Android Studio generated for the failed build on Windows and Ubuntu didn't point to any clear problem, even with --stacktrace enabled with gradle. I'm not going to waste my time figuring out why gradle doesn't want to build apps in Ubuntu or Windows.

Import Cordova project in Android Studio

I am trying to create a Cordova project. After creating the project cordova create myProject I would like to open it in Android Studio. The problem is ... it doesn't work.
The CordovaLib will not build with various errors package android.* does not exist.
Does anyone know how to import a cordova project in Android Studio?
Unfortunately the accepted answer is a bit out of date. Using Cordova v5.3.3 (it probably works on all versions > 5) it is much the same process a building and then entering XCode for an iOS application now - the build system has moved to gradle.
Before opening in Android Studio
cordova build android
Then just open up the project using File > Open and pointing to the (yourProjectDir)/Platforms/Android directory.
If you are using an older version of the cordova android platform you might need to run
cordova platform android update
To get moved to the gradle build system which is compatible with the current version of Android Studio
Make sure you import the "platform/android" directory underneath your cordova project (and you want to Import Project, not Open Project).
You will at least need to run
cordova prepare android
before doing the import
cordova build android
will also work, but it will create some ant directories which will not be used by Android Studio and you will have to actively ignore the files when importing otherwise you will get extra libraries in your project). Although I haven't imported a Cordova app into android studio recently, it definitely works in the Community edition of Intellij which Android Studio is based on (I did it yesterday with a project built from scratch with Cordova 3.5). I can't think of any of the additional features in Android Studio that would be useful that aren't in Intellij, as most of the additions which haven't been backported to Intellij are in the preview space which isn't going to work with Cordova anyway (all it is going to preview is a blank webkit view).
All the answers above seem to refer to the cli. However, to actually have your project in android studio so that you can harness the power of the android studio, this is what I would suggest you do:
Please see my most relevant answer here...
Building Ionic framework in android studio
We have some troubles on importing Ionic project to android studio because we have add android platform with SUDO command, and because of it, android studio dont have access privileges to read files.
In my case just do sudo chmod -Rf 777 ionicFolder android studio can import project successful.
I hope this help some one with this problem.

Categories

Resources