IT story

Android Studio 프로젝트에 지원 라이브러리 추가

hot-time 2020. 8. 2. 17:19
반응형

Android Studio 프로젝트에 지원 라이브러리 추가


방금 새 Android Studio를 설치했으며 Android 용 지원 라이브러리를 가져 오는 방법을 찾고 있습니다.

그 옵션은 어디에 있습니까? 이클립스에서는 두 번만 클릭하면됩니다. 나는 그것을 검색했지만 아무것도 찾지 못했습니다. 확실히 너무 새롭습니다.


더 이상 Android 프로젝트에서 더 이상 일하지 않습니다. 아래는 안드로이드 스튜디오 프로젝트를 구성하는 방법에 대한 단서를 제공하지만 완벽하게 작동한다고 보장 할 수는 없습니다.

원칙적으로 IntelliJ는 빌드 파일을 존중하며이를 사용하여 IDE 프로젝트를 구성하려고 시도합니다. 다른 방법으로는 사실이 아니며 IDE 변경은 일반적으로 빌드 파일에 영향을 미치지 않습니다.

대부분의 Android 프로젝트는 Gradle에 의해 빌드되므로 항상이 도구를 이해하는 것이 좋습니다.

@skyfishjy의 답변을 참조하는 것이 좋습니다.이 답변보다 더 업데이트 된 것 같습니다.


아래는 업데이트되지 않습니다

안드로이드 스튜디오는 IntelliJ IDEA를 기반으로하지만 APK를 빌드하려면 gradle에 의존합니다. 0.2.3 기준으로 GUI에서 구성하는 측면에서이 두 가지 기능은 잘 작동하지 않습니다. 결과적으로 GUI를 사용하여 종속성을 설정하는 것 외에도 build.gradle 파일을 수동으로 편집해야합니다.

테스트 프로젝트> 테스트 구조가 있다고 가정합니다. 찾고있는 build.gradle 파일은 TestProject / Test / build.gradle에 있습니다.

종속성 섹션을 찾아서 가지고 있는지 확인하십시오.

'com.android.support:support-v4:13.0.+'컴파일

아래는 예입니다.

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
    }
}

maven 저장소에서 타사 라이브러리를 추가 할 수도 있습니다

컴파일 그룹 : 'com.google.code.gson', 이름 : 'gson', 버전 : '2.2.4'

위의 스 니펫은 gson 2.2.4를 추가합니다.

필자의 실험에서 gradle을 추가하면 올바른 IntelliJ 종속성이 설정되는 것으로 보입니다.


============= UPDATE ==============

Android Studio는 Gradle 이라는 새로운 빌드 시스템을 도입했습니다 . 이제 Android 개발자는 단순하고 선언적인 DSL을 사용하여 Android Studio IDE와 명령 줄에서 모두 빌드하는 신뢰할 수있는 단일 빌드에 액세스 할 수 있습니다.

다음 build.gradle과 같이 편집하십시오 :

apply plugin: 'android'

    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:21.+'
    }

참고 : gradle이 항상 최신 버전을 사용할 수 있도록 +사용하십시오 compile 'com.android.support:support-v4:21.+'.

========== DEPRECATED ==========

Android Studio는 IntelliJ IDEA를 기반으로하므로 절차는 IntelliJ IDEA 12 CE와 동일합니다.

1.Open Project Structure (Press F4 on PC and Command+; on MAC) on your project).

2.Select Modules on the left pane.

3.Choose your project and you will see Dependencies TAB above the third Column.

4.Click on the plus sign in the bottom. Then a tree-based directory chooser dialog will pop up, navigate to your folder containing android-support-v4.jar, press OK.

5.Press OK.


This is way more simpler with Maven dependency feature:

  1. Open File -> Project Structure... menu.
  2. Select Modules in the left pane, choose your project's main module in the middle pane and open Dependencies tab in the right pane.
  3. Click the plus sign in the right panel and select "Maven dependency" from the list. A Maven dependency dialog will pop up.
  4. Enter "support-v4" into the search field and click the icon with magnifying glass.
  5. Select "com.google.android:support-v4:r7@jar" from the drop-down list.
  6. Click "OK".
  7. Clean and rebuild your project.

Hope this will help!


You can simply download the library which you want to include and copy it to libs folder of your project. Then select that file (in my case it was android-support-v4 library) right click on it and select "Add as Library"


In Android Studio 1.0, this worked for me :-
Open the build.gradle (Module : app) file and paste this (at the end) :-

dependencies {
    compile "com.android.support:appcompat-v7:21.0.+"
}

Note that this dependencies is different from the dependencies inside buildscript in build.gradle (Project)
When you edit the gradle file, a message shows that you must sync the file. Press "Sync now"

Source : https://developer.android.com/tools/support-library/setup.html#add-library


Android no longer downloading the libraries from the SDK manager, it has to be accessed through Google's Maven repository.

You will have to do something similar to this in your build.gradle file:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}



dependencies {
    ...
    compile "com.android.support:support-core-utils:27.0.2"
}

Find more details about the setting up process here and about the different support library revisions here.

참고URL : https://stackoverflow.com/questions/16580586/add-support-library-to-android-studio-project

반응형