LoginSignup
7
7

More than 5 years have passed since last update.

Android Studioでライブラリ依存関係を設定する方法

Last updated at Posted at 2013-08-29
  • プロジェクトルート直下にライブラリプロジェクト(SomeLibraryとする)用のフォルダ構造を作成


 ./
   App/
                src/


    SomeLibrary/

                src/

                      main/

                             java/

                                    com/...

                             AndroidManifest.xml

               build.gradle

  • build.gradleの内容は例えばこんな感じ
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:13.0.+'
}

android {
    compileSdkVersion 18
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 18
    }
}
  • 依存側のAppのbuild.gradleのdependenciesに以下のように記述


dependencies {
    ...
    compile project(':SomeLibrary')
    ...
}

  • プロジェクトルートのsettings.gradleにもincludeを追加
include ':App', ':SomeLibrary'

  • File->Project Structure->LibraryでSomeLibraryを追加

Android Studioが認識するライブラリ名にルートフォルダの名前が反映されないので手動で変更が必要。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7