| /* |
| * Copyright (C) 2022 The Android Open Source Project |
| * |
| * 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. |
| */ |
| |
| /** |
| * This file was created using the `createProject` gradle task (./gradlew createProject) |
| * |
| * Please use the task when creating a new project, rather than copying an existing project and |
| * modifying its settings. |
| */ |
| import androidx.build.SoftwareType |
| import androidx.build.AndroidXConfig |
| import org.gradle.work.DisableCachingByDefault |
| |
| import javax.inject.Inject |
| |
| plugins { |
| id("AndroidXPlugin") |
| id("com.android.library") |
| } |
| |
| /** |
| * When `reusePrebuiltsAar` is set to `true` reuses the AAR file from the ../../prebuilts directory. |
| * When `reusePrebuiltsAar` is set to `false` builds the project from scratch (from CXX) files. |
| * |
| * This was introduced to address the following issues that occurred when always building |
| * the project from scratch: |
| * - no stripping of debug symbols in 'test' configurations resulting in very large |
| * files (200+ MB total) being added to e.g. each Benchmark project (b/228627720). |
| * - no caching due to the way CMake builds are currently handled in Android Gradle Plugin |
| * resulting in always building the CXX files from scratch, which is very slow due to the |
| * size of Perfetto SDK (b/230790969). |
| * |
| * Additionally, using the prebuilts reference directly (instead of the project reference) |
| * resulted in the project not getting published to Maven or Snapshot Builds (androidx.dev). |
| */ |
| |
| def reusePrebuiltsAar = Boolean.parseBoolean( |
| System.getProperty("TRACING_PERFETTO_REUSE_PREBUILTS_AAR", "true") |
| ) |
| def prebuiltsAarVersion = androidx.LibraryVersions.TRACING_PERFETTO |
| |
| @DisableCachingByDefault |
| abstract class ExtractJniFromAar extends DefaultTask { |
| @InputFiles FileTree sourceAar |
| @OutputDirectory abstract DirectoryProperty getOutputDirectory() |
| @Inject abstract FileSystemOperations getFs() |
| |
| @TaskAction |
| void copy() { |
| outputDirectory.get().asFile.deleteDir() |
| fs.copy { copySpec -> |
| copySpec.from(sourceAar) { |
| include("jni/**") |
| // Modify the path of each file to strip the first directory ("jni") |
| eachFile { fileDetails -> |
| fileDetails.relativePath = new RelativePath( |
| !fileDetails.isDirectory(), |
| fileDetails.relativePath.segments.drop(1) as String[] |
| ) |
| } |
| // Prevent Gradle from creating the now-empty "jni" root folder |
| includeEmptyDirs = false |
| } |
| copySpec.into(outputDirectory) |
| } |
| } |
| } |
| |
| if (reusePrebuiltsAar) { |
| def extractJni = tasks.register("extractJni", ExtractJniFromAar) { |
| def zipFile = AndroidXConfig.getPrebuiltsRoot(project).toPath().resolve( |
| "androidx/internal/androidx/tracing/tracing-perfetto-binary/$prebuiltsAarVersion/" + |
| "tracing-perfetto-binary-${prebuiltsAarVersion}.aar" |
| ) |
| sourceAar = zipTree(zipFile) |
| } |
| androidComponents { |
| onVariants(selector().all()) { variant -> |
| // use extracted .so files |
| variant.sources.jniLibs.addGeneratedSourceDirectory(extractJni) { it.outputDirectory } |
| } |
| } |
| } else { |
| android { |
| // build .so files from scratch |
| externalNativeBuild { |
| cmake { |
| path "src/main/cpp/CMakeLists.txt" |
| version = libs.versions.cmake.get() |
| } |
| } |
| } |
| } |
| |
| android { |
| namespace = "androidx.tracing.perfetto.binary" |
| } |
| |
| dependencies { |
| androidTestImplementation(libs.testExtJunit) |
| androidTestImplementation(libs.testRunner) |
| androidTestImplementation(project(":benchmark:benchmark-common")) // for supported ABI checks |
| } |
| |
| androidx { |
| name = "Tracing Perfetto Binary" |
| type = SoftwareType.PUBLISHED_LIBRARY |
| inceptionYear = "2022" |
| description = "Provides native binaries required by AndroidX Tracing: Perfetto SDK " + |
| "and is not intended to be used outside of that context." |
| doNotDocumentReason = "No public API" |
| deviceTests { |
| enableAlsoRunningOnPhysicalDevices = true |
| } |
| } |