Last active
October 1, 2017 10:47
-
-
Save smyykb/37ef0e2426c48181e468dcb42732d097 to your computer and use it in GitHub Desktop.
Gradle Configration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaultConfig { | |
applicationId "com.phantomvk.app" | |
minSdkVersion 16 | |
targetSdkVersion 25 | |
versionCode 1 | |
versionName "1.0" | |
//buildConfigFieldDefined values are compiled and can be accessed in Java code BuildConfig. | |
buildConfigField "String", "BUG_REPORT_URL", "\"xx.com\"" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Yeni bir proje oluşturduğumuz zaman android studio bizim için debug ve release build type larını oluşturuyor. | |
Build tipleri kodumuzu nasıl derleceğimize karar veriyor. Örneğin apk'yı debug key ile imzalamak için configurasyon ayarlarını debug build | |
tipine göre yapıyoruz. Yada relase tipinde kodumuzun obfuscate olması için proguard dosya tanımlaması yapıyoruz. | |
Yada bir ozelliğin debug tipinde olup relase olmaması gibi tanımlamaları yapabiliriz. | |
buildTypes { | |
debug { | |
minifyEnabled false | |
} | |
release { | |
minifyEnabled true | |
shrinkResources true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.Ugulama İçinde Farklı Kanallar Oluşturmak | |
Uygulmamız aynı kalsın fakat farklı ozellikler eklemek istersek build flavor kullanıyoruz. Örneğin uygulamanın ücretli/ücretsiz | |
sürümleri farklı android versionlarında çalışsın istersek, | |
productFlavors { | |
free { | |
minSdkVersion 15 | |
targetSdkVersion 21 | |
compileSdkVersion 21 | |
} | |
paid { | |
minSdkVersion 15 | |
targetSdkVersion 24 | |
compileSdkVersion 24 | |
} | |
} | |
2.Kanal İsimlerini Farklılaştırmak | |
.apk nın paket isinin flavorlarda farklı olmasını istersek | |
applicationId "com.newlearner.app.internal" | |
yada | |
applicationIdSuffix ".internal" | |
productFlavors { | |
internal { | |
applicationIdSuffix ".internal" | |
buildConfigField "String", "TYPE", "\"Internal\"" | |
buildConfigField "String", "URL", "\"xx.com\"" | |
} | |
external { | |
buildConfigField "String", "TYPE", "\"External\"" | |
buildConfigField "String", "URL", "\"xx.com\"" | |
} | |
} | |
3. Değişken Tanımlama | |
Gradle dosyası içersinde build tipine veya product flavor bağlı değişkenler tanımlayabiliyoruz. | |
Çalıştırtığımız build varianta göre kolayca loglamayı kapatıp açabiliriz. Yada 3party uygulamaların kullandığı id/key tanımlamalarını kolaylıkla yapailiriz. | |
Build.gradle içersinde değişken tanımlamanın en buyuk faydası kodsal hiç bir değişiklik yapmadan, hangi build variantta çalıştırdıysak | |
ayarlarımızın otomatik olarak yapılması. | |
3.1.Build configuration variables: | |
gradle içerisinde "buildConfigField" ile tanımladığımız değişkenler derleme işleminde BuildConfig classının içerisnde oluşuyorlar. | |
buildConfigField "boolean", "enableDebugLogging", "false" | |
Java classları içerisinden buradaki değişkenleri kullanabiliriz. | |
if (BuildConfig.enableDebugLogging) { | |
Log.d(TAG, "Debug message here"); | |
} | |
3.2.Resource variables: | |
"resValue" ile tanımladığımız değişkenler java classları yerine resource dosyası içerisinde oluşuyorlar. | |
resValue "string", "build_type", "Release" | |
resValue "bool", "debug", "false" | |
resValue "dimen", "margin", "16dp" | |
buildTypeView.setText(R.string.build_type); | |
manifestPlaceholders = [app_key: "xyz"] | |
manifestPlaceholders = [app_secret: "abc"] | |
Android manifest.xml | |
<meta-data android:name="app_key" android:value="${app_key}" /> | |
<meta-data android:name="app_secret" android:value="${app_secret}" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Build types ve product flavors kombinasyonudur. FreeDubug modunda iken uygulamamızın free versionu debug yapabiliriz. | |
Yada uygulamanın ücretli versiyonuna store paketi çıkmak istersek PaidRelease seçerek derleme işlemini yapmalıyız. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proje seviyesindeki build.gradle içersinde tanımladığımız global variable'ları appmodule seviyesindeki build.gradle içersinden kullanabiliriz | |
ext { | |
versionCodeProp = 1 | |
versionNameProp = "1.0" | |
} | |
Module build.gradle | |
versionCode rootProject.ext.versionCodeProp | |
versionName rootProject.ext.versionNameProp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Default olarak üretilen apk isimleri | |
app-external-debug.apk | |
app-external-release-unsigned.apk | |
app-internal-debug.apk | |
app-internal-release-unsigned.apk | |
.Apk isimlerini düzenlemek istersek | |
applicationVariants.all { variant -> | |
variant.outputs.each { output -> | |
def apkName = "Sumeyye_" + "v${defaultConfig.versionName}_" + variant.productFlavors[0].name | |
if (variant.buildType.name == ('release')) { | |
apkName += '.apk' | |
} else if (variant.buildType.name == ('debug')) { | |
apkName += '_debug.apk' | |
} | |
output.outputFile = new File(output.outputFile.parent, apkName) | |
} | |
} | |
Sumeyye_v1.0_external_debug.apk | |
Sumeyye_v1.0_external.apk | |
Sumeyye_v1.0_internal_debug.apk | |
Sumeyye_v1.0_internal.apk | |
Uygulama isimlerini düzenlememiz için yapmamız gereken build flavor ile oluşan paketlerin altına res-string dosyası oluşturmak | |
ve Android manifestte kullandığımız app_name'i flavor'a uygun şekilde vermek | |
app | |
└──src | |
├──main | |
│ └──res | |
│ └──values | |
│ └──strings.xml | |
│ └──<string name="app_name">My Beautiful App</string> | |
├──internal | |
│ └──res | |
│ └──values | |
│ └──strings.xml | |
│ └──<string name="app_name">My Beautiful App-intenal</string> | |
├──external | |
│ └──res | |
│ └──values | |
│ └──strings.xml | |
│ └──<string name="app_name">My Beautiful App-external</string> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tüm versiyonlar | |
> gradle build | |
# Sadece debug modu yada relase modu | |
> gradle assembleDebug | |
> gradle assembleRelease | |
# Internal yada external kanalı | |
> gradle assembleInternal | |
> gradle assembleExternal | |
# Internal kanalı debug modu yada internal kaanlı release modu | |
> gradle assembleInternalDebug | |
> gradle assembleInternalRelease |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.2" | |
defaultConfig { | |
} | |
buildTypes { | |
debug { | |
} | |
release { | |
} | |
} | |
productFlavors { | |
internal { | |
} | |
external { | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.BuildType.html | |
http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ProductFlavor.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment