How to add Vector image support to old Android versions using new AppCompat?

Standard

Finally we had vector support for all Android versions, 8-)

  • bye bye all different PNG size files in different drawable folders!
  • bye bye FontAwesome!
  1. first of all add these dependencies to your module’s build.gradle:
dependencies {
    .
    .
    .
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-vector-drawable:23.3.0'
  1. add this to your android defaultConfig tag in your module’s build.gradle:
android {
    .
    .
    .

    defaultConfig {
        .
        .
        .
        vectorDrawables.useSupportLibrary = true
    }
  1. replace all your ImageView with android.support.v7.widget.AppCompatImageView
    and ImageButton with android.support.v7.widget.AppCompatImageButton in all your project’s xml layouts.

  2. replace all android:src attribute in all ImageView with app:srcCompat.

  3. now import your vector image using New -> “Vector Asset” submenu by right clicking on your drawable folder…

That’s it!!!

How to solve “Duplicate files copied in APK META-INF/LICENSE.txt”?

Standard

Sometimes depends on libraries that you have used in your Android project this annoying error shows up during gradle build using Android Studio:

Error:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE.txt

can be solve this issue and many more by adding this to the Android tag of your build.grade file:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}