안드로이드를 위한 Gradle 맛들이기

  • View
    2.117

  • Download
    0

Embed Size (px)

Text of 안드로이드를 위한 Gradle 맛들이기

Android Gradle

gradle 1

LG https://brunch.co.kr/@yudong https://www.facebook.com/koreacio

(2016) (2003)

10 500 (2006 ~ 2015) 2

#2 Gradle 10,000 (Daum) 3

Android Studio Gradle .

IDE Console .

Github Library .

Module Multi project .

Android Gradle . build.gradle / gradle wrapper / module / AAR / assembleDebug Build variants / settings.gradle / Transitive dependency / task 4

Gradle ? Android Gradle Dependency 5

1. Gradle ? Java, Java web projects, C, C++, Android (Facebook 20 )

Groovy Groovy DSL(Domain Specific Language)

Ant Maven Ant Ant task gradle Maven

CI 6

2. Android Gradle Android Build System Android Gradle Build.gradle Settings.gradle7

2.1 Android Build System APK !

Signing (Debug / Release) APK

8

2.2 Android Gradle ! ?

9

2.2 Android Gradle Project Build.gradleAndroid Gradle Allprojects

App() Build.gradleAndroidManifest.xml Build tools / minSDK / targetSDK / applicationId / versionCode / versionName 10

2.2 Android Gradle Settings.gradle

Gradle.properties

Local.properties SDK Home 11

2.3 IDE

>apk: /app/build/output/apk/

Console

12

2.4 Project Build.gradlebuildscript repository?jcenter? AAR mavenCentral?

allprojects repository

task

13

13

2.4 Project Build.gradleJcenter https://github.com/koush/AndroidAsync http://jcenter.bintray.com/com/koushikdutta/async/ androidasync/2.1.6/

14

14

2.4 App Build.gradleAndroidManifest.xml APK

Jar (~) AAR? Jar + Android Resources Jar ( / strings ) .

:compileSDKBuild tools versionapplicationId minSDKtargetSDKversionCodeversionName 15

15

2.4 AAR = Android Archivehttp://tools.android.com/tech-docs/new-build-system/aar-formatThe file extension is.aar, and the maven artifact type should beaaras well, but the file itself a simple zip file with the following entries:

/AndroidManifest.xml(mandatory)/classes.jar(mandatory)/res/(mandatory)/R.txt(mandatory)/assets/(optional)/libs/*.jar(optional)/jni//*.so(optional)/proguard.txt(optional)/lint.jar(optional)

apply plugin: 'com.android.library'16

16

2.4 Plugin? Gradle Task

Plugin Tasks Android, Web, POJO

apply plugin: 'com.android.application APK

apply plugin: 'com.android.library AAR

17

17

2.4 Plugins

18

18

2.5 Settings.gradle Module

5~6

include ':app', ':mylibrary

19

19

3. Dependency JAR .

gradle Gradle wrapper(gradlew)

Group / artifact ID / version !

Transitive Dependency 20

20

3.1 Library Github library gradle

AndroidAsync: https://github.com/koush/AndroidAsync

ButterKnife: https://github.com/JakeWharton/butterknife

21

21

3.2 App Build.gradle .

dependencies { compile 'com.koushikdutta.async:androidasync:2.1.5}

IDE Sync Now

22

22

3.2 Console

dependencies { compile 'com.koushikdutta.async:androidasync:2.1.5}

23

23

3.2

24

24

3.3 ? ? Dependency

!

gradlew :app:dependencies

25

25

3.4 Transitive Dependency Gradle Maven, Apache IVY

) Hibernate core library : Gradle In Action, 107pageHibernate-core-3.6.3-final.jarHibernate-commons-annotations-3.2.0-final.jarSlf4j-1.5.8.jarSlf4j-1.6.1.jarVersion Conflict26

26

3.5 DependencyGradle Include

) Omni Notes: https://github.com/federicoiosue/Omni-Notes

compiledebugCompileandroidTestCompilereleaseCompileprovidedCompile 27

27

3.6 Omni Notes

androidTestCompilefileTree@aarAndroid ArchiveexcludegroupnameversiondebugCompile releaseCompile 28

28

3.7 Gradle . ? ( Gradle )

+

29

29

3.8 Gradle dependencies ./gradlew :app:denpendencies .

30

30

4. Multi Project App Module Library Module

Library Module

Library AAR 31

31

4.1 Library Project ModuleApp Module APK Library Module AAR

Android Studio > File > New > New Module

Build.gradle

Settings.gradle

32

32

4.2 App App Build.gradle

1)

dependencies { compile project(:mylibrary) }

33

33

4.2 App App Build.gradle

2) AAR repositories { jcenter() flatDir { dirs 'libs' } }

dependencies { compile 'com.example.mylibrary:mylibrary-debug:1.0@aar' }

34

34

4.3 Library :mylibrary LibraryMain.java Activity

35

35

4

Local Repository : AAR libs jCentral()

Build Variants : Build type(debug / release) Full version / Demo version product flavors

36

36

5. Apk

Console task

Gradle daemon

APK folder 37

37

5.1 APK App(Module) Build.gradle

buildTypes { applicationVariants.all { variant -> variant.outputs.each { output -> output.outputFile = new File( output.outputFile.parent, output.outputFile.name.replace(".apk", "-${variant.versionName}.apk")) } }

38

38

5.2 Task Console.. > ./gradlew :app:asD assembleDebug > ./gradlew :app:cl clean

> ./gradlew :app:aD

39

39

5.3 Gradle Daemon Gradle JVM daemon

> ./gradlew --daemon :app:aD ..

1st : 58.4 2nd: 2.8

daemon

40

40

5.4 APK APK folder Module build.gradle

task publish(dependsOn: 'assembleRelease')