2

I'm trying to run an open source project in Android Studio 2.0. My problem is that I can't import the class IoBridge (import libcore.io.IoBridge;). The compiler is saying that libcore does not exist. And effectively in my SDK (revision 23) there is not the library named libcore. Below is the code.

/*
 *  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

buczek
  • 2,011
  • 7
  • 29
  • 40
pape
  • 47
  • 7

1 Answers1

2

Apparently, that code is designed to built as part of the system firmware, not from an Android SDK app. libcore is not available to Android SDK app developers.

Specifically, based on the screenshot, you appear to be attempting to compile java.net.Socket from the Android Open Source Project, which is not designed to be compiled as part of an Android app.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Thank you for this information. Now how can I do ? should I create a external Library for importing the libcore? if yes How? – pape Apr 28 '16 at 13:40
  • @pape: Most likely, you should not be attempting to use this code in the first place. You are welcome to build your own custom ROM that contains a modified version of `java.net.Socket`, then install that custom ROM on your device. Or, consider subclassing `Socket`, rather than trying to reimplement it. – CommonsWare Apr 28 '16 at 13:41
  • And if I try to add the Library libcore in the SDK sources, Why doesnt it work? ( – pape Apr 28 '16 at 14:06
  • @pape: The SDK sources are designed to be build as part of building the firmware for a ROM, or for an Android SDK tied to that firmware. You cannot use arbitrary AOSP classes in an Android SDK app. – CommonsWare Apr 28 '16 at 14:17
  • Actually I use the socket.java which is in the sdk , and in this socket.java there is an import (import libcore.io.IoBridge). – pape Apr 28 '16 at 14:34
  • @pape: Correct. You cannot compile that source code in an Android SDK app. You should not need to compile that source code in an Android SDK app, as the Android SDK already has `java.net.Socket`. You cannot replace `java.net.Socket` from the Android SDK in your app. – CommonsWare Apr 28 '16 at 14:36
  • I dont compile the java.net.Socket, but when I try to debugg my project it go to this class .. And What I dont understand is why java.net.Socket use an import (libcore.io.IoBridge) which doest not exist in the SDK? – pape Apr 28 '16 at 14:53
  • @pape: "What I dont understand is why java.net.Socket use an import (libcore.io.IoBridge) which doest not exist in the SDK? " -- many classes in the Android SDK use classes and methods that are not part of the Android SDK. The Android SDK is an API. The implementation of any API is substantially more complex than the API itself and will use things that are not directly part of the API. In this case, given that the Android SDK is an API for an operating system, the situation is even more complex. – CommonsWare Apr 28 '16 at 14:56
  • Ok I ses Thank you very much – pape Apr 28 '16 at 17:43