Add support library to Android Studio project

后端 未结 6 2034
天涯浪人
天涯浪人 2020-11-30 19:24

I just installed the new Android Studio and I\'m looking for a way to import the support library for Android.

Where is the option for that? In Eclipse that are just

6条回答
  •  抹茶落季
    2020-11-30 19:59

    I no longer work on Android project for a while. Although the below provides some clue to how an android studio project can be configured, but I can't guarantee it works flawlessly.

    In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It's not true in the other way round, IDE changes normally will not affect the build file.

    Since most Android projects are built by Gradle, it's always a good idea to understand this tool.

    I'd suggest referring to @skyfishjy's answer, as it seems to be more updated than this one.


    The below is not updated

    Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn't play nicely in term of configuring from GUI. As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.

    Assuming you have a Test Project > Test structure. The build.gradle file you're looking for is located at TestProject/Test/build.gradle

    Look for the dependencies section, and make sure you have

    compile 'com.android.support:support-v4:13.0.+'

    Below is an example.

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.5.+'
        }
    }
    apply plugin: 'android'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile 'com.android.support:support-v4:13.0.+'
    }
    
    android {
        compileSdkVersion 18
        buildToolsVersion "18.0.1"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 16
        }
    }
    

    You can also add 3rd party libraries from the maven repository

    compile group: 'com.google.code.gson', name: 'gson', version: '2.2.4'

    The above snippet will add gson 2.2.4 for you.

    In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.

提交回复
热议问题