简体   繁体   中英

Android Studio - how to use libraries (from eclipse projects)

Yes. Everybody are testing Android Studio. I'm using Eclipse in my projects and I want to migrate to Android Studio. I'm having problems with my projects.

I read this page: http://developer.android.com/sdk/installing/migrate.html

Not a great how to in my opinion.

I'm using in my project libraries that are not in .jar formats but they're eclipse projects (with checked "is library" in properties).

Could you tell me how to move my projects to Android Studio? I'm having problems and tons of errors. I'm also using Google Play Services and Android Studio showed me old versions of the same API's.

How to add for example ActionBarSherlock or Android-ViewPagerIndicator?

Shoud I import just like in eclipse all of these projects. But in Android Studio I can't mark project as library or not?

  1. Open the Project Structure (cmd-; on osx or just File > Project Structure)
  2. Go to facets
  3. Select the module (the project you imported)
  4. there will be a "library module " checkbox at the top

This worked for me.

In the build.gradle file:

dependencies {
    compile files('libs/android-support-v4.jar')
    compile project(':MyLibrary')
}

And, in the IntelliJ Module file, HelloWorld.iml:

<orderEntry type="library" name="android-support-v4" level="application" />
<orderEntry type="library" name="MyLibrary.aar" level="project" />

In the library project, there's not much to do: tell Gradle and Android Studio that this is an Android library, with apply plugin: 'android-library' and option name=”LIBRARY_PROJECT” value=”true” , respectively.

To use Google Play Services: In the build.gradle file:

dependencies {
    compile 'com.google.android.gms:play-services:4.2.42'
}

In the AndroidManifest.xml file:

<application >
    <meta-data 
        android:name="com.google.android.gms.version" 
        android:value="@integer/google_play_services_version" />
</application>

I actually had the android:value="4242000" but AndroidStudio auto-corrected it to the above, which compiles, so I left it, since it is less fragile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM