Program Club

Cordova 플랫폼 Android 대상을 나열하는 동안 작동하지 않는 Android 추가

proclub 2020. 10. 17. 12:33
반응형

Cordova 플랫폼 Android 대상을 나열하는 동안 작동하지 않는 Android 추가


phoneGap 애플리케이션에 Android 플랫폼을 추가하고 싶을 때 문제가 발생했습니다. cordova platform add android 명령을 실행할 때 CLI에이 메시지가 표시됩니다.

Checking Android requirements... (Error: An error occurred while listing Android targets)

이미 경로 변수에 Android SDK 위치를 추가하려고합니다.

제발 도와주세요! :디

저는 Windows 7 64 비트에서 작업하고 Android SDK와 함께 Android API 17, 18 및 19를 설치합니다. 3.2 phoneGap 버전입니다.


작동하려면이 cordova 명령은 sdk/tools디렉토리 에있는 일부 프로그램을 사용해야합니다 . 또한 Apache ant를 설치해야합니다 .

그런 다음 다음 디렉토리를 PATH시스템 변수에 추가해야합니다 .

배경:

  • Android SDKc:\sdk\android디렉토리에 설치했다고 가정하겠습니다.
  • 당신은 당신이 설치 한 아파치 개미를 받는 c:\tools\apache-ant디렉토리

그런 다음 두 개의 시스템 변수를 만들어야합니다.

  1. ANDROID_HOMEc:\sdk\android가치 와 함께
  2. ANT_HOMEc:\tools\apache-ant가치 와 함께

마지막으로, PATH변수 를 수정 하고 PATH'값 끝에이 두 가지를 추가 해야합니다 .

;%PATH%\tools;%ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

참고 : Linux를 사용하는 경우 지침이 약간 다릅니다.

여기에서 더 많은 문서를 볼 수 있습니다 .


Linux 개발 환경을 선호하는 사람들을 위해

요구 사항

우선 시작하려면 몇 가지 사항이 필요합니다. 그들은 다음 Android SDK과 같습니다 Apache Ant. 물론 Java SDK(JDK)가 설치되어 있어야합니다.

모든 사용자에 대해 Android SDK가 작동하도록하려면 /etc/environment파일 을 수정 한 다음 PC를 다시 시작해야합니다. 그러나 그렇게 어려운 길을 원하지 않는다면 나를 따르십시오. 자신을 유일한 PC 사용자로 생각하십시오. 그리고 /home/YOUR_USERNAME/.bashrc파일을 사용 하여 편집하십시오.

더 이상 긴 줄을 피하기 위해 집 경로를 한 번 기억합시다. 다음을 추가하십시오 /home/YOUR_USERNAME/.bashrc:

export HOME="/home/YOUR_USERNAME"

그런 다음 $HOME" /home/YOUR_USERNAME directory" 을 말할 때 표기법 을 사용합니다 .

Android SDK 설정

Android SDK 아카이브를 다운로드하고 어딘가에 압축을 풉니 다. 예를 들어, 홈 디렉토리, $HOME/adt-bundle/.

다음 줄을 추가하십시오 $HOME/.bashrc.

export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

Ant 설정

Android SDK와 마찬가지로 아카이브를 다운로드하고 홈 디렉토리에 압축을 풉니 다. 그런 다음 다음을 추가하십시오 .bashrc.

export ANT_HOME="$HOME/ant"
export PATH="$PATH:$ANT_HOME/bin"

를 통해 하나를 설치 apt-get했으므로 .bashrc.

변경 사항 적용

이러한 변경 사항을 적용하려면 새 터미널 창 ( 변경 열림 )에서 작업하거나 source ~/.bashrc현재 터미널 창에서 변경 사항을 사용할 수 있도록 실행 해야합니다.

마무리

마지막에 다음을 얻게됩니다.

  1. 홈 디렉토리에 두 개의 디렉토리- antandroid-bundle
  2. 다음 항목에 몇 줄이 추가되었습니다 .bashrc.

    export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
    export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
    export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
    
    export ANT_HOME="$HOME/ant"
    export PATH="$PATH:$ANT_HOME/bin"
    

adt \ sdk \ tools 폴더에서 "android"명령을 실행하고 최신 도구 및 SDK를 설치합니다. 또한 PATH에 올바른 변수가 있는지 확인하십시오.

이를 위해서는 ANT를 설치하고 JAVA JDK 및 Android SDK를 설치해야합니다.

JAVA_HOME (C : \ Program Files \ Java \ jdk)

ANT_HOME ({ant location} \ apache \ apache-ant)

ANDROID_HOME ({android sdk 위치} \ android-sdk)

Add these to your PATH variable like %ANT_HOME%/bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;%JAVA_HOME%\bin

Close and re-open your cmd and run your command again.

Similiar to PhoneGap/Cordova Android Development


I'm not sure if this is your problem, but I've encountered similar errors when the cordova library cache gets polluted with something corrupted. To fix it, you just need to delete the cordova cache, and it will automatically repopulate next time you use 'cordova'.

On OS X, this directory is ~/.cordova. On Windows, I assume it's .cordova in your users home directory still.


The answer is "All of the Above". Do as mentioned with the environment variables, however, also do this:

C:\Users{YOUR_NAME}.cordova\lib\android\cordova\3.5.0\framework edit the project.properties file and change target=android-19 to target=android-20.

Presumably this will need to be changed for the next rendition of android sdk's as well until this little issue gets resolved.


I had the same issue even though path variables were set exactly as per the instructions. After going through multiple files I finally got it resolved. For me (Windows 7 enterprise 64 bit) I had to modify check_reqs.js and create.js from "C:\Users\.cordova\lib\android\cordova\3.5.0\bin\lib\" folder to include absolute path for the android.bat. My android SDK is under "C:\Android\android-sdk".

In check_reqs.js I modified

child_process.exec('android list targets', function(err, stdout, stderr) {

to

child_process.exec('C:\\Android\\android-sdk\\tools\\android.bat list targets', function(err, stdout, stderr) {

In create.js I modified the statement

return exec('android update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');

to

return exec('C:\\Android\\android-sdk\\tools\\android.bat update project --subprojects --path "' + projectPath + '" --target ' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');

Also do not forget those double "\\" in the absolute path


after a long struggle, after doing all of the above suggestions more then once with growing desperation, i simply openned my cmd as administrator. it worked. i guess i just got too used for "sudo" before i got this pc.


For those who have encountered this problem I add something extra that can be helpful, in my case had all the variables properly configured and this was still unable to add android platform and I did was disable my avast antivirus and puff! everything flowed smoothly, what was happening was that the antivirus was blocking the creation of the platform.

Also important for me was to restart the pc. ;)

Regards.


I noticed the problem with Cygwin/Windows 7. The problem stems from the slightly different ways Cygwin and MS-DOS shells treat .bat files.

During "add platform", cordova invokes "android":

C:\Users\xxx\.cordova\lib\android\cordova\3.4.0\bin\lib\check_reqs.js

Where it calls 'android list targets' (on line 73)

"android" should resolve to /xx/android-sdk/tools/android.bat or xx:\android-sdk\tools\android.bat. (And, in fact it does, I can run "android" on the MS-DOS command shell - but not in Cygwin shell. There I need to add ".bat".)

"android" without ".bat" fails in Cygwin shell because android.exe doesn't exist (only .bat does). Changing line 73 to invoke 'android.bat list targets' will solve your problem (or give a reasonable error message).

Another work-around is to run cordova in a MS-DOS shell instead of Cygwin shell.


We have a list of solutions here, so I add my one. That was not clear for me until I just try. You should add %ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools to USER PATH variable, not to a System one. System PATH variable will automatically concatenate the USER PATH variable and translate variables to its value. Hope that helps somebody. P.S. My OS is Win 7x64


This problem is usually cause because of PATH variable has not been set for Android SDK.

export HOME="/home/yourname"
export ANDROID_HOME="$HOME/android-bundle/sdk/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-bundle/sdk/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"
export ANT_HOME="$HOME/ant"
export PATH="$PATH:$ANT_HOME/bin"

Accepted answer is good and to the point.

I have come across another page where its very well explained with screen shots.

You can refer http://bealers.com/2014/06/phonegap-android-development-environment-for-windows/

참고URL : https://stackoverflow.com/questions/20323787/cordova-platform-add-android-not-working-while-listing-android-targets

반응형