/*
 * Copyright (C) 2005-2017 Qihoo 360 Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed To in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

/**
 * 插件编译脚本
 *
 * @author RePlugin Team
 */
apply plugin: 'com.android.application'

android {
    compileSdkVersion androidExt['compileSdkVersion']
    buildToolsVersion androidExt['buildToolsVersion']

    defaultConfig {
        versionName "1.1"
        versionCode 104
        minSdkVersion androidExt['minSdkVersion']
        targetSdkVersion androidExt['targetSdkVersion']
        applicationId "com.qihoo360.replugin.sample.demo1"
        multiDexEnabled false
    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

// 这个plugin需要放在android配置之后，因为需要读取android中的配置项
apply plugin: 'replugin-plugin-gradle'
repluginPluginConfig {
    // enable = true // 是否启用插件功能，默认为true
    classExcludes = ["androidx.*"]
    // classExcludes = ["com.qihoo360.replugin.sample.demo1.*"]
    // classIncludes = ["com.qihoo360.replugin.sample.demo1.BaseActivity"]
    pluginName = "demo1"
    hostApplicationId = "com.qihoo360.replugin.sample.host"
    hostAppLauncherActivity = "com.qihoo360.replugin.sample.host.MainActivity"
}

dependencies {
    implementation dependenciesExt['replugin-plugin-library']

    // 错误导入，会报错：
    // Android dependency 'androidx.fragment:fragment:1.0.0' is set to compileOnly/provided which is not supported
    // 报错本质：
    // compileOnly/provided 只能用于依赖 jar，不能用于 aar 。
    // 而 compileOnly 'androidx.appcompat:appcompat:1.0.0' 会同时依赖n个其他androidx库（包括fragment、lifecycle...），这些会被认定为是 compileOnly aar
    // 解决方案参考：
    // https://github.com/Qihoo360/RePlugin/issues/557
    // https://github.com/luohaoxuan320/RePluginDemo/wiki/%E6%8F%92%E4%BB%B6-AppCompatActivity-%E4%B8%8E-v4.Fragment%E5%85%B1%E5%AD%98
    // compileOnly dependenciesExt['appcompat-androidx']

    // 注：有 classExcludes 之后，不再使用这种方式，直接 implementation 第三方库即可！！
//    // 这个jar就是从Androidx-fragment中提取出来的并非特制包目的是为了骗过编译期
//    compileOnly files('libs/androidx-fragment.jar')
//    // androidx-fragment 需要依赖的其他jar包 begin ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
//    compileOnly files('libs/androidx-lifecycle-common-2.4.0.jar')
//    compileOnly files('libs/androidx-lifecycle-viewmodel.jar')
//    compileOnly files('libs/androidx-activity.jar')
//    compileOnly files('libs/androidx-savedstate.jar')
//    // androidx-fragment 需要依赖的其他jar包 end ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
    implementation dependenciesExt['appcompat-androidx']

    compileOnly files('libs/common-utils-lib-1.0.0.jar') //这 个jar就是从Host的utils中编译生成的，其目的是为了骗过编译期

    implementation(name: 'plugin-library', ext: 'aar') // sample:compile aar
    // implementation project(":library")
}

if (android.defaultConfig.multiDexEnabled) {
    apply from: 'case.gradle'
}
