2016-04-28 288 views
1

我试图在Android Studio 2.0中运行一个开源项目。我的问题是我无法导入IoBridge类(import libcore.io.IoBridge;)。编译器说libcore不存在。有效地在我的SDK(修订版23)中没有名为libcore的库。以下是代码。无法导入库libcore.io.IoBridge

/* 
* Licensed to the Apache Software Foundation (ASF) under one or more 
* contributor license agreements. See the NOTICE file distributed with 
* this work for additional information regarding copyright ownership. 
* The ASF licenses this file to You under the Apache License, Version 2.0 
* (the "License"); you may not use this file except in compliance with 
* the License. You may obtain a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License. 
*/ 

package java.net; 

import java.io.Closeable; 
import java.io.FileDescriptor; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.nio.channels.SocketChannel; 
import libcore.io.IoBridge; 

enter image description here

回答

1

显然,该代码被设计成内置的系统固件的一部分,而不是从Android SDK应用程序。 Android SDK应用程序开发人员无法使用libcore

具体而言,根据屏幕截图,您似乎试图从Android开源项目中编译java.net.Socket,该项目并非旨在作为Android应用程序的一部分进行编译。

+0

感谢您提供此信息。现在我该怎么办?我应该创建一个用于导入libcore的外部库吗?如果是的话如何? – pape

+0

@pape:最有可能的是,您不应该首先尝试使用此代码。欢迎您构建自己的自定义ROM,其中包含修改后的“java.net.Socket”版本,然后将该自定义ROM安装在您的设备上。或者,考虑子类化'Socket',而不是试图重新实现它。 – CommonsWare

+0

如果我尝试在SDK资源中添加库libcore,为什么它不起作用? ( – pape