Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2018-present [email protected]
*
* 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.
*/
package com.yy.android.gradle.nativedepend
import com.android.build.gradle.api.AndroidSourceSet
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.artifacts.ArtifactCollection
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactScope
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ArtifactType
import com.android.build.gradle.internal.publishing.AndroidArtifacts.ConsumedConfigType
import org.gradle.api.artifacts.ArtifactView
import org.gradle.api.artifacts.ResolvedArtifact
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.Configuration
import org.apache.commons.io.FileUtils
import org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import static com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE
import org.gradle.api.Action
import org.gradle.api.attributes.AttributeContainer
import org.gradle.api.specs.Spec
import org.gradle.api.file.FileTree
import com.yy.android.gradle.nativedepend.util.DependenciesUtils
import com.android.build.gradle.internal.dsl.ProductFlavor
class NativeBundleImportPlugin implements Plugin {
private static final String[] APP_ABIS = ["armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64"]
private static String intermediatesDirName = "nativeLib"
protected Project project
void apply(Project project) {
this.project = project
createExtension()
File intermediatesDir = new File(project.buildDir, intermediatesDirName)
File gradleMk = new File(intermediatesDir, "gradle.mk")
defaultNativeBundle.ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK = gradleMk
if (!gradleMk.parentFile.exists()) gradleMk.parentFile.mkdirs()
gradleMk.createNewFile()
def variants
if (android.class.name.find("com.android.build.gradle.AppExtension") != null ||
android.class.name.find("com.android.build.gradle.internal.dsl.BaseAppModuleExtension") != null) {
variants = android.applicationVariants
} else if (android.class.name.find("com.android.build.gradle.LibraryExtension") != null) {
variants = android.libraryVariants
} else {
println(":${project.name}:Only support android gradle plugin")
return
}
/*Important!
When the flavor's/buildType native build configure is the same, the gradle
will not generate per build script for per flavor/buildType and it will optimize
the build speed[AGP 7.0], but in our plugin, whe should need every build script,
because native dependency may different in different flavor/buildType, so we add
dummy flags to native build, so gradle will generate every build script
*/
android.productFlavors.whenObjectAdded { ProductFlavor it ->
it.externalNativeBuild.ndkBuild.cFlags("-D${it.name.capitalize()}")
it.externalNativeBuild.cmake.cFlags("-D${it.name.capitalize()}")
}
android.buildTypes.each {
it.externalNativeBuildOptions.cmake.cFlags("-D${it.name.capitalize()}")
it.externalNativeBuildOptions.ndkBuild.cFlags("-D${it.name.capitalize()}")
}
variants.whenObjectAdded { variant ->
String gradleMkPath
if (!variant.flavorName.isEmpty()) {
gradleMkPath = "${variant.flavorName}/${variant.buildType.name}/gradle.mk"
}else {
gradleMkPath = "${variant.buildType.name}/gradle.mk"
}
gradleMk = new File(intermediatesDir, gradleMkPath)
if (!gradleMk.parentFile.exists()) gradleMk.parentFile.mkdirs()
gradleMk.createNewFile()
String ndkDefine = "ANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK=${gradleMk.path.replace("\\", "/")}"
String cmakeDefine = "-DANDROID_GRADLE_NATIVE_BUNDLE_PLUGIN_MK=${gradleMk.path.replace("\\", "/")}"
GradleApiAdapter.addArgumentToNativeBuildOption(project, variant, ndkDefine, cmakeDefine)
}
project.afterEvaluate {
variants.all { variant ->
hookVariant(variant)
}
}
project.tasks.getByName("clean").doLast {
// clean task will delete the files, so we should recreate
if (!intermediatesDir.exists()) {
intermediatesDir.mkdirs()
println(":${project.name}:re pull native bundle file")
variants.each { variant ->
hookVariant(variant)
}
}
}
}
private void hookVariant(def variant) {
try {
Map> linkLibs = [:]
Set wholeStaticLibs = []
Set includeDirs = []
Map nativeLibs = [:]
Map sos = [:]
Map hars = [:]
Set excludeDependenciesList = []
Set