Android Studio-android.jar和rt.jar冲突 [英] Android Studio - android.jar and rt.jar conflicts

查看:353
本文介绍了Android Studio-android.jar和rt.jar冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio 2.1.2开发一个Android应用程序.

I’m developing an Android Application with Android Studio 2.1.2.

在外部库(尤其是IBM Bluemix的Watson库, com.ibm.watson.developer_cloud:java-sdk:3.0.1 )的类之一中,我需要导入这些库三个类别:

In one of the classes of an external library (in particular the Watson library of IBM Bluemix, com.ibm.watson.developer_cloud:java-sdk:3.0.1) I need to import these three classes:

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

问题是这些导入是不可能的(无法解析符号).这是我的情况:

The problem is that these importations are not possible (Cannot resolve symbols). This is my scenario:

android.jar

rt.jar

当我尝试导入javax程序包时,我只会看到 android.jar 中的程序包(加密,微型版本,网络,安全性,sql,xml).我没有看到 rt.jar 中的那些,所以我无法使用 javax.naming 中存在的类包.

我试图以这种方式显式添加依赖项

I’ve tried to explicitly add the dependency in this way

compile files ('C:/Program Files/Java/jdk1.8.0_77/jre/lib/rt.jar')

但是我认为这是不正确的,实际上它可以编译,但是由于此错误,我无法在设备上运行:

but I think this is not correct, in fact it compiles but I can’t run on the device because of this error:

Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1

这是我在这篇文章中遇到的相同问题:无法访问Javax内容,但这一次,问题与请求导入的特定Watson库无关.

It’s the same problem I’ve encountered in this post: Javax content not accessible, but this time the problem is independent from the specific Watson Library that request the importations.

使类可见以使应用程序正常工作的方法是什么?

What is the way to make visible that classes to let the application work?

推荐答案

您不能在Android应用程序中使用 rt.jar (与 android.jar 有点重叠).那是桌面JRE而不是Android的运行时库.请参阅 Android API参考,以获取可用软件包的列表(您会注意到 javax.naming 不是其中之一.

You cannot use rt.jar with an Android application (and somewhat overlaps with android.jar). That is the runtime library for the desktop JRE, not Android. Please see the Android API reference for a list of available packages (you'll notice that javax.naming is not one of them.

很明显,IBM框架与Android不兼容.

我的先前评估不准确,因为自述文件明确指出:

My earlier assessment is inaccurate as the README clearly states that it is:

该库支持Android 2.3及更高版本.对于Java,最低要求为1.7.这取决于OkHttp和gson.

The library supports Android 2.3 and above. For Java, the minimum requirement is 1.7. It depends on OkHttp and gson.

源.

但是,我怀疑该问题与配置错误的凭据有关(请参阅

However, I suspect the issue is related to incorrectly configured credentials (see here) causing the library to then attempt JNDI lookup as a fallback (which definitely isn't supported by Android).

这篇关于Android Studio-android.jar和rt.jar冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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