android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错

Posted learnframework

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错相关的知识,希望对你有一定的参考价值。

1、make idegen

build completed successfully (32 seconds)

2、执行 development/tools/idegen/idegen.sh脚本

test@test-Lenovo:~/aosp$ development/tools/idegen/idegen.sh 
find: 'out/target/product/emulator_x86_64/root/d': Permission denied

这里大家看到这里Permission denied很多同学可能就立即停止了然后用sudo命令:

sudo development/tools/idegen/idegen.sh

结果报错如下:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread “main” java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader 1. r u n ( U R L C l a s s L o a d e r . j a v a : 363 ) a t j a v a . s e c u r i t y . A c c e s s C o n t r o l l e r . d o P r i v i l e g e d ( N a t i v e M e t h o d ) a t j a v a . n e t . U R L C l a s s L o a d e r . f i n d C l a s s ( U R L C l a s s L o a d e r . j a v a : 362 ) a t j a v a . l a n g . C l a s s L o a d e r . l o a d C l a s s ( C l a s s L o a d e r . j a v a : 418 ) a t s u n . m i s c . L a u n c h e r 1.run(URLClassLoader.java:363) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:362) at java.lang.ClassLoader.loadClass(ClassLoader.java:418) at sun.misc.Launcher 1.run(URLClassLoader.java:363)atjava.security.AccessController.doPrivileged(NativeMethod)atjava.net.URLClassLoader.findClass(URLClassLoader.java:362)atjava.lang.ClassLoader.loadClass(ClassLoader.java:418)atsun.misc.LauncherAppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

大概看者报错意思就是idegen.jar的编译java版本是 version 53.0即java 9
但是执行时候是 versions up to 52.0即java8 这个到底为啥?
我们看看当前java版本是不是java8

test@test-Lenovo:~/aosp$ java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment android_PDK (build 11.0.4+0-6508549)
OpenJDK 64-Bit Server VM Android_PDK (build 11.0.4+0-6508549, mixed mode)

这里明明展示是11啊,完全可以啊,为啥呢?
这里我们想想,我们因为是以sudo来执行的,所以是不是sudo这个用户导致问题:

test@test-Lenovo:~/aosp$ sudo java -version
[sudo] password for test: 
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~20.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

哦哦这里一看果然是这样

那么解决办法目前就采用
直接执行 . development/tools/idegen/idegen.sh (注意多了.空格哦)忽略Permission denied 其实也是可以正常生成对应.iml 和 ipr文件

test@test-Lenovo:~/aosp$ . development/tools/idegen/idegen.sh 
find: 'out/target/product/emulator_x86_64/root/d': Permission denied
Read excludes: 16ms
Traversed tree: 120376ms


Android手机大厂Framework系统-Input系统专题实战课
https://ke.qq.com/course/4963459

[入门课,实战课,跨进程专题
ps需要学习深入framework课程和课程优惠
新课程优惠获取请加入qq群:422901085(获取demo源码)

以上是关于android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio导入系统源码及配置

android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错

Android:导入所需的系统jar包到Android studio

Android 11使用Android Studio调试系统应用:编译SettingsLib模块导入子模块解决编译错误

android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错

android studio导入android系统源码 development/tools/idegen/idegen.sh执行报错