如何从InetAddress.java(或libcore / luni / src / main / java / java / net中的任何文件)导入android.util.Log? [不是] [英] How Can I Import android.util.Log from InetAddress.java (or any file in libcore/luni/src/main/java/java/net)? [Not a]

查看:614
本文介绍了如何从InetAddress.java(或libcore / luni / src / main / java / java / net中的任何文件)导入android.util.Log? [不是]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法直接使用以下任何一种语句

I cannot directly use either of the following statements

import android.util.Log; 

import android.os.Environment;

来自libcore / luni / src / main / java / java / net中的InetAddress.java,也不能我使用任何依赖它的文件。我正在使用的一个组成员创建了一个依赖于android.os.Environment的类,并在AOSP的其他地方成功使用了它,例如packages / apps / PackageInstaller / src / com / android / packageinstaller / PackageInstallerActivity。 java

from InetAddress.java in libcore/luni/src/main/java/java/net, nor can I use any file which depends on it. A member of a group that I am working with has created a class which depends on android.os.Environment and has used it successfully in other places in AOSP such as packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

我不是100%肯定没有其他方法来完成他创建的课程要完成的任务,但出于一致性的目的,我会如果可能的话,我更愿意在InetAddress.java中重复使用他的代码。

I'm not 100% certain there are not alternative methods to accomplish the tasks that the class he created is intended to accomplish, but for purposes of consistency I'd prefer to re-use his code in InetAddress.java if at all possible.

我收到的错误消息是

Error: no package named android.os
Error: no package named android.util 

我发现此资源在谷歌搜索解决方案后,建议删除这些行以便能够从标准库导入 LOCAL_NO_STANDARD_LIBRARY = true;

I found this resource after searching for solutions on Google which suggested removing these lines to be able to import from standard libraries LOCAL_NO_STANDARD_LIBRARY = true;

按照这个建议,我搜索了最接近InetAddress.java的父目录,该目录有一个Android.mk文件,并尝试编辑它,看到它没有行说明 LOCAL_NO_STANDARD_LIBRARY = true;
但它确实调用了包含这些行的JavaLibrary.mk。在将它们注释掉并重建之后,运行make后输出中出现以下行:

Following this advice, I searched for parent directory closest to InetAddress.java which has an Android.mk file and tried editing it, saw that it had no lines that said LOCAL_NO_STANDARD_LIBRARY = true; but it did call JavaLibrary.mk which did contain those lines. After commenting them out and rebuilding, the following lines appeared in the output after running make:

make: Circular out/target/common/obj/JAVA_LIBRARIES/framework-base_intermediates/classes-full-debug.jar <- out/target/common/obj/JAVA_LIBRARIES/bouncycastle_intermediates/classes.jar dependency dropped.
make: Circular out/target/common/obj/JAVA_LIBRARIES/framework-base_intermediates/classes-full-debug.jar <- out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes.jar dependency dropped.
make: Circular out/target/common/obj/JAVA_LIBRARIES/framework-base_intermediates/classes-full-debug.jar <- out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar dependency dropped.
make: Circular out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/classes-full-debug.jar <- out/target/common/obj/JAVA_LIBRARIES/conscrypt_intermediates/classes.jar dependency dropped.
make: Circular out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/classes-full-debug.jar <- out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar dependency dropped.
make: *** [out/target/common/obj/JAVA_LIBRARIES/core-junit_intermediates/classes-full-debug.jar] Error 41
make: *** Waiting for unfinished jobs....
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
make: *** [out/target/common/obj/JAVA_LIBRARIES/okhttp_intermediates/classes-full-debug.jar] Error 41
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
make: *** [out/target/common/obj/JAVA_LIBRARIES/ext_intermediates/classes-full-debug.jar] Error 41

如果有必要,我可以发布完整的输出,但这些线是看起来唯一的线条不能成为构建过程的正常输出的一部分。

I can post the full make output if it's necessary, but these lines are the only lines that seem to not be part of the normal output of the build process.

首先提供替代使用android.os的答案或评论当然是值得赞赏的,因为这是后备,但我宁愿让这些进口工作,如果可能的话。

Answers or comments which provide alternatives to using android.os in the first place are certainly appreciated as that is the fallback, but I'd prefer to get these imports working if at all possible.

推荐答案

oblem是Makefiles无法正常工作......对于你正在尝试做的事情。

The problem is that the Makefiles are not working properly ... for what you are trying doing.

这些错误:

Error: no package named android.os
Error: no package named android.util 

...表示当编译器编译 InetAddress.java 时,这些包不在类路径中。我怀疑这是设计;即,避免或最小化Java子集包和Android特定包之间的循环依赖性。您似乎正在尝试对 InetAddress 进行或注入更改以打破该构建假设;即,它们在模块之间创建循环依赖关系,这些模块旨在以有序/部分有序的顺序构建。

... mean that those packages are not on the classpath when the compiler is compiling InetAddress.java. I suspect that this is by design; i.e. to avoid or minimize circular dependencies between the Java-subset packages and the Android-specific packages. It appears that you are trying to make or inject changes to InetAddress that break that build assumption; i.e. they create a circular dependencies between modules that are intended to be built in a ordered / partially ordered sequence.

然后这个:

Fatal Error: Unable to find package java.lang in classpath 
             or bootclasspath

说你做得更糟。但它指向相同的总体方向 - 编译时类路径问题。

says that you've made things worse. But it is pointing in the same general direction - a compile time classpath problem.

如何修复它?

坦率地说,我不知道是否可以修复。但如果有可能的话,很可能需要重新修改android模块化及其makefile。

Frankly, I don't know if it can be fixed. But if it is possible, it is likely to entail significant reworking of the android modularization and its makefiles.

注意:这个进口在语言层面的运作方式不是问题。这完全是关于编译器在哪里寻找要导入的类(即 javac 命令行选项告诉它看起来)以及这些类是什么已编译(尚)。

Note: this is not an issue with how imports work at the linguistic level. It is all about where the compiler is looking for classes to import (i.e. where the javac command line options told it to look) and whether those classes have been compiled (yet).

这篇关于如何从InetAddress.java(或libcore / luni / src / main / java / java / net中的任何文件)导入android.util.Log? [不是]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆