blob: 11f465592a4a45938e57df4804d7a935559f8854 [file] [log] [blame]
/*
* 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.
*/
import androidx.build.Publish
import androidx.build.SupportConfigKt
plugins {
id("AndroidXPlugin")
id("com.android.library")
id("kotlin-android")
}
/**
* 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
def unzippedPrebuiltsAarDir = "$buildDir/unzipped-aar"
if (reusePrebuiltsAar) {
def unzipTask = tasks.register("unzipPrebuiltsAarDir", Copy) {
def zipFile = SupportConfigKt.getPrebuiltsRoot(project).toPath().resolve(
"androidx/internal/androidx/tracing/tracing-perfetto-binary/$prebuiltsAarVersion/" +
"tracing-perfetto-binary-${prebuiltsAarVersion}.aar"
)
from zipTree(zipFile)
into file(unzippedPrebuiltsAarDir)
}
tasks.findByName("preBuild").dependsOn(unzipTask)
}
android {
if (reusePrebuiltsAar) {
sourceSets {
main.jniLibs.srcDirs += new File(unzippedPrebuiltsAarDir, "jni")
}
} else { // build .so files from scratch
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version libs.versions.cmake.get()
}
}
}
namespace "androidx.tracing.perfetto.binary"
}
dependencies {
androidTestImplementation(libs.kotlinStdlib)
androidTestImplementation(libs.testExtJunit)
androidTestImplementation(libs.testRunner)
}
androidx {
name = "AndroidX Tracing: Perfetto SDK Native Dependencies"
publish = Publish.SNAPSHOT_AND_RELEASE
mavenVersion = LibraryVersions.TRACING_PERFETTO
mavenGroup = LibraryGroups.TRACING
inceptionYear = "2022"
description = "Provides native binaries required by AndroidX Tracing: Perfetto SDK " +
"and is not intended to be used outside of that context."
}