If anyone could help me understand some things regarding Android Studio, it would be most enlightening.
So, I have switched from Eclipse to Android Studio around a month ago and so far have only been working on my migrated Apps. As such, I have been tinkering around with only the AndroidManifest.xml file as was customary in Eclipse.
However, recently, I have started creating a new project for the sake of learning Android Studio's differences from Eclipse from ground up. Aside from the very irritating appcompat_v7 issues I have encountered, I'm also confused with some things regarding build.gradle.
Below is a gradle code block from an app created from Android Studio:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.myapp"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:mediarouter-v7:22.2.0'
}
On the other hand, below is a code block from build.gradle of a migrated Eclipse project:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':google-play-services_lib')
}
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Am I right in some of the assumptions I have taken from reading?
compileSdkVersion - must always use the highest for maximum compatibility to newer phones?
targetedSdkVersion - my own preference on the optimal run conditions of my app?
buildToolsVersion - I read this must ALWAYS be using the latest version. Can someone explain why?
Now to my questions with regards to manifest vs gradle:
Do compile & buildtools version have to be the same? Can they be different?
If I have both an AndroidManifest.xml and a build.gradle, how does Android Studio know which to use for the compile,min,targeted,buildtools versions?
As an extension to question 1, what happens when there is a discrepancy between the 2 files (if someone forgot for some reason and decided to add stuff in one of them?)
Since there are duplicate attributes between the 2, does this mean that starting with apps generated from Android Studio, I don't need to touch AndroidManifest.xml at all?
What about the
<activity></activity>
so the app doesn't force close when it can't find the activity? Does build.gradle take care of that automatically? Or controlling orientation and other finer features (am I stuck with modifying only the java files on Android Studio?)(if it doesn't, then having 2 files to control the app is kind of redundant and maybe they should have just stuck to AndroidManifest.xml?)
Sorry for the long, maybe winding, questions but it really is quite confusing to me.
Thanks in advance.
Update:
After reading What is Gradle in Android Studio? and http://developer.android.com/tools/studio/index.html, my new questions:
AndroidManifest.xml is still needed, build.gradle just overrides settings if it has the same attributes.
Question: So BOTH are still needed in Android Studio, correct?
compile & buildtools version DON'T have to be the same BUT buildtools must always be higher than compileSdkVersion.
Question: Is this because Google creates a new buildtools version for each new Sdk and the higher version are backward compatible? Therefore, higher buildtools will build lower compileSdkVersion while the reverse is not true, correct?