development

Gradle, Android 및 ANDROID_HOME SDK 위치

big-blog 2020. 6. 14. 09:39
반응형

Gradle, Android 및 ANDROID_HOME SDK 위치


편집 : (2016 년 8 월)

이 질문은 2013 년 11 월부터 (Android Studio는 여전히 개발자 미리보기 모드에 있음),

설치 중 현재 (AS v2.2, 2016 년 8 월) AS는 SDK 폴더를 선택하라는 메시지를 표시하거나 (또는 ​​기본 설치) 설치중인 프로젝트에 자동으로 적용됩니다.

즉, 문제를 더 이상 재현 할 수 없으므로 가능한 해결 방법이나 수정은 관련이 없습니다.

원래 질문 :

우리는 래퍼를 사용하여 다른 개발자 PC에서 이미 구성되고 올바르게 실행되는 여러 모듈을 가진이 프로젝트를 가지고 있습니다. 완전한 git 서브 모듈을 머신에 복제했습니다.

아래는 내 명령 줄을 직접 인쇄 한 것입니다.

$ ./gradlew

FAILURE: Build failed with an exception.

* Where:
Build file '/home/budius/project_name/ActionBar-PullToRefresh/library/build.gradle' line: 1

* What went wrong:
A problem occurred evaluating project ':ActionBar-PullToRefresh:library'.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

* 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: 6.378 secs

$ echo $ANDROID_HOME
/home/budius/Applications/android-studio/sdk
$ 

보시다시피 ANDROID_HOME이 있습니다. 그들은 무엇을 원합니까? 여기서 무엇이 잘못 되었습니까?

우분투 13.04에서 실행

편집하다:

이미 sdk.dir=<path>프로젝트 루트에 local.properties 파일을 작성 했으며 작동합니다. 그러나 이로 인해 시스템 빌드 서버에서 코드를 이식하기가 더 어려워 지므로 여전히 의문의 여지가 있습니다.

ANDROID_HOME이 작동하지 않는 이유와 작동하게하려면 어떻게해야하는지 아는 사람이 있습니까?


문제를 해결했습니다. 이것은 나를 위해 작동합니다 :

/ my_current_project /

local.properties 라는 파일을 만들고 내부에 넣었습니다.

sdk.dir = / my_current_path_to / sdk

콘솔에서해야 할 일

ANDROID_HOME = / my_current_path_to / sdk 설정

도움이 되었기를 바랍니다.


OSX 에서 IntelliJ는 .bash_profile 또는 .bash_rc 등에서 설정 한 환경 변수를 선택하지 않습니다.

자신의 SDK 위치 값을 대체하여 이것을 시도하십시오.

launchctl setenv ANDROID_HOME /usr/local/opt/android-sdk

그런 다음 IntelliJ를 다시 시작하면 Bob이 삼촌입니다.

더 일반적으로 언급 된 문제에 대한 참조는 다음과 같습니다. https://emmanuelbernard.com/blog/2012/05/09/setting-global-variables-intellij/


제 경우 settings.gradle에는 실종되었습니다.

파일을 저장하고 프로젝트의 최상위 폴더에 저장하십시오. 다른 프로젝트에서도 복사 할 수 있습니다.

스크린 샷 참조 :

여기에 이미지 설명을 입력하십시오

이것이 당신의 시간을 절약하기를 바랍니다.


이것은 나를 위해 작동합니다 :

$ export ANDROID_HOME=/path_to_sdk/
$ ./gradlew

Android Gradle 플러그인은 아직 베타 버전이며 버그 일 수 있습니다. 나를 위해 ANDROID_HOME을 설정해도 작동하지만 다른 버전 일 수 있습니다 (가장 최신 버전으로 다시 시도하고 작동하는지 알려주세요).

ANDROID_HOME뿐만 아니라 환경 변수 ANDROID_SDK도 설정하는 것이 좋습니다.

I have seen issues with this on some machines, so we do create local.properties in those cases - I have also noticed that the latest version of Android Studio will create this file for you and fill in the sdk.dir property.

Note that you shouldn't check local.properties into version control, we have added it to our gitignore so that it doesn't interfere with porting the code across systems which you rightfully identified as a potential problem.


For whatever reason, the gradle script is not picking up the value of ANDROID_HOME from the environment. Try specifying it on the command line explicitly

$ ANDROID_HOME=<sdk location> ./gradlew

I faced the same issue, though I had local.properties file in my main module, and ANDROID_HOME environment variable set at system level.

What fixed this problem was when I copied the local.properties file which was in my main project module to the root of the whole project (i.e the directory parent to your main module)

Try copying the local.properties file inside modules and the root directory. Should work.


I came across the same problem when opening a cloned git repository. The local.properties file is automatically added to the .gitignore file as it is specific to the build environment of each machine and is therefore not part of the repo.

The solution is to import the project instead of just opening it after you have cloned it from git, this forces android studio to create the local.properties file specific to your machine:

File >> Import Project >>


MAC OSX:

  1. Open up Terminal and edit the file:

~/.bash_profile

to add:

export ANDROID_HOME=~/Library/Android/sdk export PATH=${PATH}:${ANDROID_HOME}/tools export PATH=${PATH}:${ANDROID_HOME}/platform-tools

  1. Run:

    source ~/.bash_profile

  2. Restart the Terminal and Android Studio


How to do it on MAC OSX:

1) Open up Terminal, and Edit: vi ~/.bash_profile If there is no file there, just add it.

2) Add (Change to YOUR USER NAME and add this):

#Java var home: JAVA_HOME="/usr/libexec/java_home" ANDROID_HOME="/Users/<YOUR USER NAME>/Library/Android/sdk"

3) Run source ~/.bash_profile.

4) Run echo $JAVA_HOME; echo $ANDROID_HOME;

5) If your output is:

/usr/libexec/java_home /Users/<YOUR USER NAME>/Library/Android/sdk

So you are good.

and RESTART android studio!

And, Make sure that you have java :)

java -version

And gradle :)

gradle --version


Copy the local.properties to root folder and run again.


This worked for me (Ubuntu):

Add ANDROID_HOME=/path/to/android-sdk to /etc/environment.

Reboot.


in windows, I set ANDROID_HOME=E:\android\adt-bundle-windows-x86_64-20131030\sdk Then it works as expect.

When in Linux, you need to set sdk.dir.

The script uses two different variables.


I have the same problem, seems the sample code can not find the android environment, instead to try to fix that I just remove the sample code from settings.gradle and then the installation goes fine.

after that just import the project in eclipse and that's all :)


In Linux, try to run studio.sh from a terminal and set the ANDROID_HOME in this terminal. This worked for me.


If you are using windows plantform, please try run Android Studio as Administrator


Just delete the sdk.dir inside the local.preoperties file and set the ANDROID_HOME environment variable . It worked for me.


export ANDROID_HOME=/xxx/xxx/ in shell, then use it by System.env.ANDROID_HOME in gradle file.

PS: don't forget the 'export' keywords to make the ANDROID_HOME global.


Your local.properties file might be missing. If so add a file named 'local.properties' inside /local.properties and provide the sdk location as following.

sdk.dir=C:\Users\\AppData\Local\Android\Sdk


I have just solved the exact same issue by adding the ANDROID_HOME as a system wide variable. In Ubuntu it should be in /etc/profile or in a shell script file in /etc/profile.d/

Then logout and login again, now Gradle should recognize the ANDROID_HOME variable.


I came across a similar problem. Somehow, I did not have a build folder in my project. By copying this folder from another project to my project I was having an issue with, this fixed this problem.


Installing Build-Tools 23.0.1 instead of 23.0.2 fixed this issue for me.


solutions:

1 add "sdk.dir=path_of_sdk"

2 execute gradlew with evn variable like following:

$ANDROID_HOME=path_of_sdk ./gradlw


You said that versioning local.properties creates problems for you. I've hacked together a script which uses android command line tool to refresh the local.properties file across the machines that are involved in the production. The android update project command, besides the local.properties produces a lot of unwanted trash (at least for me) which is the reason for all those rm commands at the end of the script.

#!/bin/bash
scname="$0"
echo "${scname}: updating local properties..."
ln -fs src/main/AndroidManifest.xml
android update project -t 24 -p "$(pwd)"
echo "${scname}: ...done"
echo "${scname}: removing android update project junk ..."
rm -v project.properties
rm -v build.xml
rm -v proguard-project.txt
rm -v AndroidManifest.xml
echo "${scname}: ...done"

This script is the first thing we run on any new machine where we code. It has to be run in the root project directory. Of course, android studio may have a GUI way of dealing with this, but I wouldn't know as I use a different editor. I also can't claim that the solution is general, but it "Works For Me" (tm).


I have faced with the same issue on Ubuntu(both local.properties and ANDROID_HOME was added), but build fail persisted. So workaround is to add following lines

export ANDROID_HOME=/home/<user>/Android/Sdk export PATH=$PATH:/home/<user>/Android/Sdk/tools

directly to the studio.sh script (inside /usr/local/android-studio/bin)

Maybe it will be helpful.


i encountered the same error but in my case i was cloning a project, the cloned project was built with Android API 22 which i did not install at the time(i had API 24 and 25 installed)........so i had to download the sdk tools for API 22


For Windows:

  1. Add ANDROID_HOME to the Environment Variables: ANDROID_HOME = C:/Users/YOUR_USERNAME/AppData/Local/Android/sdk
  2. Add %ANDROID_HOME%\platform-tools to the PATH.

That question is from November 2013 (while Android Studio was still in Developer Preview mode),

설치 중 현재 (AS v2.2, 2016 년 8 월) AS는 SDK 폴더를 선택하라는 메시지를 표시하거나 (또는 ​​기본 설치) 설치중인 프로젝트에 자동으로 적용됩니다.

즉, 문제를 더 이상 재현 할 수 없으므로 가능한 해결 방법이나 수정은 관련이 없습니다.

참고 URL : https://stackoverflow.com/questions/19794200/gradle-android-and-the-android-home-sdk-location

반응형