Simplify Flac extension build process
Removed `Android.mk` and `Application.mk`, allowing `CMake` to run directly from the build.gradle file. Users no longer need to check out `NDK` or depend on it, simplifying the usage of the Flac extension. Also fixed a copy-pasted comment in `CMakeLists.txt` of Opus and IAMF. PiperOrigin-RevId: 684769561
This commit is contained in:
parent
a2eda3348b
commit
c78abaac3f
@ -17,7 +17,7 @@ To use the module you need to clone this GitHub project and depend on its
|
|||||||
modules locally. Instructions for doing this can be found in the
|
modules locally. Instructions for doing this can be found in the
|
||||||
[top level README][].
|
[top level README][].
|
||||||
|
|
||||||
In addition, it's necessary to build the module's native components as follows:
|
In addition, it's necessary to fetch libflac as follows:
|
||||||
|
|
||||||
* Set the following environment variables:
|
* Set the following environment variables:
|
||||||
|
|
||||||
@ -26,30 +26,24 @@ cd "<path to project checkout>"
|
|||||||
FLAC_MODULE_PATH="$(pwd)/libraries/decoder_flac/src/main"
|
FLAC_MODULE_PATH="$(pwd)/libraries/decoder_flac/src/main"
|
||||||
```
|
```
|
||||||
|
|
||||||
* Download the [Android NDK][] and set its location in an environment variable.
|
* Fetch libflac:
|
||||||
This build configuration has been tested on NDK r21.
|
|
||||||
|
|
||||||
```
|
|
||||||
NDK_PATH="<path to Android NDK>"
|
|
||||||
```
|
|
||||||
|
|
||||||
* Download and extract flac-1.3.2 as "${FLAC_MODULE_PATH}/jni/flac" folder:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
cd "${FLAC_MODULE_PATH}/jni" && \
|
cd "${FLAC_MODULE_PATH}/jni" && \
|
||||||
curl https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.2.tar.xz | tar xJ && \
|
git clone https://github.com/xiph/flac.git libflac
|
||||||
mv flac-1.3.2 flac
|
|
||||||
```
|
```
|
||||||
|
|
||||||
* Build the JNI native libraries from the command line:
|
* [Install CMake][]
|
||||||
|
|
||||||
```
|
Having followed these steps, gradle will build the module automatically when run
|
||||||
cd "${FLAC_MODULE_PATH}"/jni && \
|
on the command line or via Android Studio, using [CMake][] and [Ninja][] to
|
||||||
${NDK_PATH}/ndk-build APP_ABI=all -j4
|
configure and build libflac and the module's [JNI wrapper library][].
|
||||||
```
|
|
||||||
|
|
||||||
[top level README]: ../../README.md
|
[top level README]: ../../README.md
|
||||||
[Android NDK]: https://developer.android.com/tools/sdk/ndk/index.html
|
[Install CMake]: https://developer.android.com/studio/projects/install-ndk
|
||||||
|
[CMake]: https://cmake.org/
|
||||||
|
[Ninja]: https://ninja-build.org
|
||||||
|
[JNI wrapper library]: src/main/jni/flac_jni.cc
|
||||||
|
|
||||||
## Build instructions (Windows)
|
## Build instructions (Windows)
|
||||||
|
|
||||||
|
@ -17,13 +17,19 @@ android {
|
|||||||
namespace 'androidx.media3.decoder.flac'
|
namespace 'androidx.media3.decoder.flac'
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
|
||||||
jniLibs.srcDir 'src/main/libs'
|
|
||||||
jni.srcDirs = [] // Disable the automatic ndk-build call by Android Studio.
|
|
||||||
}
|
|
||||||
androidTest.assets.srcDir '../test_data/src/test/assets'
|
androidTest.assets.srcDir '../test_data/src/test/assets'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
arguments "-DWITH_OGG=OFF"
|
||||||
|
arguments "-DINSTALL_MANPAGES=OFF"
|
||||||
|
targets "flacJNI"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated
|
// TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated
|
||||||
// to version 8.5.1 or higher.
|
// to version 8.5.1 or higher.
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
@ -33,6 +39,22 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Configure the native build only if libflac is present to avoid gradle sync
|
||||||
|
// failures if libflac hasn't been built according to the README instructions.
|
||||||
|
if (project.file('src/main/jni/libflac').exists()) {
|
||||||
|
android.externalNativeBuild.cmake {
|
||||||
|
path = 'src/main/jni/CMakeLists.txt'
|
||||||
|
version = '3.21.0+'
|
||||||
|
if (project.hasProperty('externalNativeBuildDir')) {
|
||||||
|
if (!new File(externalNativeBuildDir).isAbsolute()) {
|
||||||
|
ext.externalNativeBuildDir =
|
||||||
|
new File(rootDir, it.externalNativeBuildDir)
|
||||||
|
}
|
||||||
|
buildStagingDirectory = "${externalNativeBuildDir}/${project.name}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(modulePrefix + 'lib-decoder')
|
implementation project(modulePrefix + 'lib-decoder')
|
||||||
// TODO(b/203752526): Remove this dependency.
|
// TODO(b/203752526): Remove this dependency.
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2016 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
WORKING_DIR := $(call my-dir)
|
|
||||||
|
|
||||||
# build libflacJNI.so
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
include $(WORKING_DIR)/flac_sources.mk
|
|
||||||
|
|
||||||
LOCAL_PATH := $(WORKING_DIR)
|
|
||||||
LOCAL_MODULE := libflacJNI
|
|
||||||
LOCAL_ARM_MODE := arm
|
|
||||||
LOCAL_CPP_EXTENSION := .cc
|
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := \
|
|
||||||
$(LOCAL_PATH)/flac/include \
|
|
||||||
$(LOCAL_PATH)/flac/src/libFLAC/include
|
|
||||||
LOCAL_SRC_FILES := $(FLAC_SOURCES)
|
|
||||||
|
|
||||||
LOCAL_CFLAGS += '-DPACKAGE_VERSION="1.3.2"' -DFLAC__NO_MD5 -DFLAC__INTEGER_ONLY_LIBRARY
|
|
||||||
LOCAL_CFLAGS += -D_REENTRANT -DPIC -DU_COMMON_IMPLEMENTATION -fPIC -DHAVE_SYS_PARAM_H
|
|
||||||
LOCAL_CFLAGS += -O3 -funroll-loops -finline-functions -DFLAC__NO_ASM '-DFLAC__HAS_OGG=0'
|
|
||||||
|
|
||||||
LOCAL_LDLIBS := -llog -lz -lm
|
|
||||||
# Enable 16 KB ELF alignment.
|
|
||||||
LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384"
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
@ -1,20 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2016 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
APP_OPTIM := release
|
|
||||||
APP_STL := c++_static
|
|
||||||
APP_CPPFLAGS := -frtti
|
|
||||||
APP_PLATFORM := android-14
|
|
51
libraries/decoder_flac/src/main/jni/CMakeLists.txt
Normal file
51
libraries/decoder_flac/src/main/jni/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2024 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
|
||||||
|
|
||||||
|
# Enable C++11 features.
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
|
||||||
|
# Define project name for your JNI module
|
||||||
|
project(libflacJNI C CXX)
|
||||||
|
|
||||||
|
set(libflac_jni_root "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
# Build libflac.
|
||||||
|
add_subdirectory("${libflac_jni_root}/libflac"
|
||||||
|
EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
|
# Build libflacJNI.
|
||||||
|
add_library(flacJNI
|
||||||
|
SHARED
|
||||||
|
flac_jni.cc
|
||||||
|
flac_parser.cc)
|
||||||
|
|
||||||
|
# Add the include directory from libflac.
|
||||||
|
include_directories("${libflac_jni_root}/libflac/include")
|
||||||
|
|
||||||
|
# Locate NDK log library.
|
||||||
|
find_library(android_log_lib log)
|
||||||
|
|
||||||
|
# Link libflacJNI against used libraries.
|
||||||
|
target_link_libraries(flacJNI
|
||||||
|
PRIVATE android
|
||||||
|
PRIVATE FLAC
|
||||||
|
PRIVATE ${android_log_lib})
|
||||||
|
|
||||||
|
# Enable 16 KB ELF alignment.
|
||||||
|
target_link_options(flacJNI
|
||||||
|
PRIVATE "-Wl,-z,max-page-size=16384")
|
@ -1,45 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2016 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
FLAC_SOURCES = \
|
|
||||||
flac_jni.cc \
|
|
||||||
flac_parser.cc \
|
|
||||||
flac/src/libFLAC/bitmath.c \
|
|
||||||
flac/src/libFLAC/bitreader.c \
|
|
||||||
flac/src/libFLAC/bitwriter.c \
|
|
||||||
flac/src/libFLAC/cpu.c \
|
|
||||||
flac/src/libFLAC/crc.c \
|
|
||||||
flac/src/libFLAC/fixed.c \
|
|
||||||
flac/src/libFLAC/fixed_intrin_sse2.c \
|
|
||||||
flac/src/libFLAC/fixed_intrin_ssse3.c \
|
|
||||||
flac/src/libFLAC/float.c \
|
|
||||||
flac/src/libFLAC/format.c \
|
|
||||||
flac/src/libFLAC/lpc.c \
|
|
||||||
flac/src/libFLAC/lpc_intrin_avx2.c \
|
|
||||||
flac/src/libFLAC/lpc_intrin_sse2.c \
|
|
||||||
flac/src/libFLAC/lpc_intrin_sse41.c \
|
|
||||||
flac/src/libFLAC/lpc_intrin_sse.c \
|
|
||||||
flac/src/libFLAC/md5.c \
|
|
||||||
flac/src/libFLAC/memory.c \
|
|
||||||
flac/src/libFLAC/metadata_iterators.c \
|
|
||||||
flac/src/libFLAC/metadata_object.c \
|
|
||||||
flac/src/libFLAC/stream_decoder.c \
|
|
||||||
flac/src/libFLAC/stream_encoder.c \
|
|
||||||
flac/src/libFLAC/stream_encoder_framing.c \
|
|
||||||
flac/src/libFLAC/stream_encoder_intrin_avx2.c \
|
|
||||||
flac/src/libFLAC/stream_encoder_intrin_sse2.c \
|
|
||||||
flac/src/libFLAC/stream_encoder_intrin_ssse3.c \
|
|
||||||
flac/src/libFLAC/window.c
|
|
@ -19,15 +19,15 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// libFLAC parser
|
||||||
|
#include <FLAC/stream_decoder.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// libFLAC parser
|
#include "../include/data_source.h"
|
||||||
#include "FLAC/stream_decoder.h"
|
|
||||||
|
|
||||||
#include "include/data_source.h"
|
|
||||||
|
|
||||||
typedef int status_t;
|
typedef int status_t;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ add_library(iamfJNI
|
|||||||
# Locate NDK log library.
|
# Locate NDK log library.
|
||||||
find_library(android_log_lib log)
|
find_library(android_log_lib log)
|
||||||
|
|
||||||
# Link libgav1JNI against used libraries.
|
# Link libiamfJNI against used libraries.
|
||||||
target_link_libraries(iamfJNI
|
target_link_libraries(iamfJNI
|
||||||
PRIVATE android
|
PRIVATE android
|
||||||
PRIVATE iamf
|
PRIVATE iamf
|
||||||
|
@ -39,7 +39,7 @@ add_library(opusV2JNI
|
|||||||
# Locate NDK log library.
|
# Locate NDK log library.
|
||||||
find_library(android_log_lib log)
|
find_library(android_log_lib log)
|
||||||
|
|
||||||
# Link libgav1JNI against used libraries.
|
# Link libopusJNI against used libraries.
|
||||||
target_link_libraries(opusV2JNI
|
target_link_libraries(opusV2JNI
|
||||||
PRIVATE android
|
PRIVATE android
|
||||||
PRIVATE opus
|
PRIVATE opus
|
||||||
|
Loading…
x
Reference in New Issue
Block a user