java 构建 Android 源代码时如何修复 JDK not found 错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17988110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 19:46:15  来源:igfitidea点击:

How do I fix JDK not found error when building Android source?

javaandroidubuntuandroid-source

提问by IHeartAndroid

I am trying to build the Android source by the steps provided here.However I have troubles with my JDK. When launching:

我正在尝试按照此处提供的步骤构建Android 源代码。但是我的 JDK 有问题。启动时:

lunch full-eng

I get the following error:

我收到以下错误:

/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: build/core/find-jdk-tools-jar.sh: Permission denied
build/core/config.mk:344: *** Error: could not find jdk tools.jar, please install JDK6, which you can download from java.sun.com.  Stop.    
** Don't have a product spec for: 'full'
** Do you have the right repo manifest?

So I tried to install the JDK correctly by the following steps:

所以我尝试通过以下步骤正确安装JDK:



Step 1

步骤1

Uninstall everything JAVA related by following these steps.

按照以下步骤卸载与 JAVA 相关的所有内容。

Step 2

第2步

Install correct JAVA by following these steps. I used the default installer option and version 6, not 7 or 8

按照以下步骤安装正确的 JAVA 。我使用了默认安装程序选项和版本 6,而不是 7 或 8

Step 3

第 3 步

Here I am simply following this answer.

在这里,我只是按照这个答案。

sudo gedit .bashrc

Edit the file at the bottom by adding those lines

通过添加这些行来编辑底部的文件

JAVA_HOME=/usr/lib/jvm/java-6-oracle
export JAVA_HOME

# replacing /path/to/androidsdk/ with correct path of course..
export PATH=${PATH}:/path/to/androidsdk/android-sdk-linux/platform-tools

PATH=$PATH:$JAVA_HOME

# Variable ANDROID_JAVA_HOME
ANDROID_JAVA_HOME=/usr/lib/jvm/java-6-oracle
export ANDROID_JAVA_HOME

PATH=$PATH:$ANDROID_JAVA_HOME

Step 4

步骤4

Test what I've done so far:

测试我到目前为止所做的:

...:~$ echo $JAVA_HOME
/usr/lib/jvm/java-6-oracle
...:~$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Server VM (build 20.45-b01, mixed mode)
...:~$ which java
/usr/bin/java
...:~$ echo $ANDROID_JAVA_HOME
/usr/lib/jvm/java-6-oracle
...:~$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-oracle/bin:/usr/lib/jvm/java-6-oracle/db/bin:/usr/lib/jvm/java-6-oracle/jre/bin:/path/to/androidsdk/android-sdk-linux/platform-tools:/usr/lib/jvm/java-6-oracle

Step 5

第 5 步

Go in terminal to the Android source folder and enter

在终端中进入 Android 源文件夹并输入

source build/envsetup.sh

Result:

结果:

including device/asus/grouper/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/armv7-a/vendorsetup.sh
including device/generic/mips/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/samsung/maguro/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/samsung_slsi/arndale/vendorsetup.sh
including device/samsung/toroplus/vendorsetup.sh
including device/samsung/toro/vendorsetup.sh
including device/ti/panda/vendorsetup.sh

Step 6

第 6 步

Go in terminal to the Android source folder and enter

在终端中进入 Android 源文件夹并输入

lunch full-eng

Result:

结果:

.../androidsource$ lunch full-eng
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-gcc: Permission denied
/bin/bash: build/core/find-jdk-tools-jar.sh: Permission denied
build/core/config.mk:344: *** Error: could not find jdk tools.jar, please install JDK6, which you can download from java.sun.com.  Stop.

** Don't have a product spec for: 'full'
** Do you have the right repo manifest?


What did I do wrong? What is missing? What about the "Permission denied"?

我做错了什么?缺什么?“权限被拒绝”怎么办?

采纳答案by IHeartAndroid

I found the solution:

我找到了解决方案:

  1. For some reason I did not have the respective rights as the "Permission denied" would suggest. Setting the permissions for the Android source folder via chmod did the trick

  2. I mistakenly downloaded the latest branch. However I only have a 32 bit system. For 32 bit you can only use Android source that is smaller than Android 2.3 and for those versions you also have to use JDK 5 http://source.android.com/source/building.html

  1. 出于某种原因,我没有“权限被拒绝”所暗示的相应权利。通过 chmod 设置 Android 源文件夹的权限就成功了

  2. 我错误地下载了最新的分支。但是我只有一个 32 位系统。对于 32 位,您只能使用小于 Android 2.3 的 Android 源,对于这些版本,您还必须使用 JDK 5 http://source.android.com/source/building.html

回答by Moorthi Daniel

I had same problem. I got it resolved it my changing the file permission for entire android source code folder:

我有同样的问题。我解决了它,我更改了整个 android 源代码文件夹的文件权限:

sudo chmod 755 -R ~/Android

回答by Joey Troy

Also had the same problem but it was due to an NTFS issue as I was not able to execute from the partition. Here is the fix I found.

也有同样的问题,但这是由于 NTFS 问题,因为我无法从分区执行。这是我找到的修复程序。

https://askubuntu.com/questions/164847/cant-compile-in-ntfs-partition

https://askubuntu.com/questions/164847/cant-compile-in-ntfs-partition

回答by Varun Bhatia

Usually, this is caused by javac is not configured as a alternative for system. So there is no link of /usr/bin/javac for your javac.

通常,这是由于 javac 没有配置为 system 的替代方案造成的。因此,您的 javac 没有 /usr/bin/javac 的链接。

Please setup the alternative for javac using the following command:

请使用以下命令为 javac 设置替代方案:

$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.6.0_32/bin/javac" 1

note: the installed directory of javac for me is "/usr/lib/jvm/jdk1.6.0_32/", you can change it by your configuration.

注意:我的javac安装目录是“/usr/lib/jvm/jdk1.6.0_32/”,可以根据自己的配置修改。

回答by Rabindra

I also came across with same situation. I activated root user and logged-in and did the same what is mention at http://source.android.com/source/building.htmlsite and it worked flawlessly.

我也遇到了同样的情况。我激活了 root 用户并登录并执行了http://source.android.com/source/building.html站点上提到的相同操作,并且它完美无缺地工作。