diff --git a/.gitattributes b/.gitattributes
index 030ef14..e27f70f 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,3 @@
*.pbxproj -text
# specific for windows script files
-*.bat text eol=crlf
\ No newline at end of file
+*.bat text eol=crlf
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
new file mode 100644
index 0000000..6e42fec
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -0,0 +1,67 @@
+name: 🐛 Bug report
+description: Report a reproducible bug or regression in this library.
+labels: [bug]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ # Bug report
+
+ 👋 Hi!
+
+ **Please fill the following carefully before opening a new issue ❗**
+ *(Your issue may be closed if it doesn't provide the required pieces of information)*
+ - type: checkboxes
+ attributes:
+ label: Before submitting a new issue
+ description: Please perform simple checks first.
+ options:
+ - label: I tested using the latest version of the library, as the bug might be already fixed.
+ required: true
+ - label: I tested using a [supported version](https://github.com/reactwg/react-native-releases/blob/main/docs/support.md) of react native.
+ required: true
+ - label: I checked for possible duplicate issues, with possible answers.
+ required: true
+ - type: textarea
+ id: summary
+ attributes:
+ label: Bug summary
+ description: |
+ Provide a clear and concise description of what the bug is.
+ If needed, you can also provide other samples: error messages / stack traces, screenshots, gifs, etc.
+ validations:
+ required: true
+ - type: input
+ id: library-version
+ attributes:
+ label: Library version
+ description: What version of the library are you using?
+ placeholder: "x.x.x"
+ validations:
+ required: true
+ - type: textarea
+ id: react-native-info
+ attributes:
+ label: Environment info
+ description: Run `react-native info` in your terminal and paste the results here.
+ render: shell
+ validations:
+ required: true
+ - type: textarea
+ id: steps-to-reproduce
+ attributes:
+ label: Steps to reproduce
+ description: |
+ You must provide a clear list of steps and code to reproduce the problem.
+ value: |
+ 1. …
+ 2. …
+ validations:
+ required: true
+ - type: input
+ id: reproducible-example
+ attributes:
+ label: Reproducible example repository
+ description: Please provide a link to a repository on GitHub with a reproducible example.
+ validations:
+ required: true
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
new file mode 100644
index 0000000..5bc358e
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/config.yml
@@ -0,0 +1,8 @@
+blank_issues_enabled: false
+contact_links:
+ - name: Feature Request 💡
+ url: https://github.com/exzos28/react-native-audio-analyzer/discussions/new?category=ideas
+ about: If you have a feature request, please create a new discussion on GitHub.
+ - name: Discussions on GitHub 💬
+ url: https://github.com/exzos28/react-native-audio-analyzer/discussions
+ about: If this library works as promised but you need help, please ask questions there.
diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml
index fb98c79..a613332 100644
--- a/.github/actions/setup/action.yml
+++ b/.github/actions/setup/action.yml
@@ -5,13 +5,13 @@ runs:
using: composite
steps:
- name: Setup Node.js
- uses: actions/setup-node@v3
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version-file: .nvmrc
- - name: Cache dependencies
+ - name: Restore dependencies
id: yarn-cache
- uses: actions/cache@v3
+ uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
**/node_modules
@@ -25,3 +25,12 @@ runs:
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --immutable
shell: bash
+
+ - name: Cache dependencies
+ if: steps.yarn-cache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
+ with:
+ path: |
+ **/node_modules
+ .yarn/install-state.gz
+ key: ${{ steps.yarn-cache.outputs.cache-primary-key }}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0c7ff3c..30a92d3 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup
uses: ./.github/actions/setup
@@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup
uses: ./.github/actions/setup
@@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup
uses: ./.github/actions/setup
@@ -56,13 +56,16 @@ jobs:
TURBO_CACHE_DIR: .turbo/android
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup
uses: ./.github/actions/setup
+ - name: Generate nitrogen code
+ run: yarn nitrogen
+
- name: Cache turborepo for Android
- uses: actions/cache@v3
+ uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-android-${{ hashFiles('yarn.lock') }}
@@ -79,7 +82,7 @@ jobs:
- name: Install JDK
if: env.turbo_cache_hit != 1
- uses: actions/setup-java@v3
+ uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
with:
distribution: 'zulu'
java-version: '17'
@@ -91,7 +94,7 @@ jobs:
- name: Cache Gradle
if: env.turbo_cache_hit != 1
- uses: actions/cache@v3
+ uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: |
~/.gradle/wrapper
@@ -107,18 +110,22 @@ jobs:
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
build-ios:
- runs-on: macos-14
+ runs-on: macos-latest
env:
+ XCODE_VERSION: 16.2
TURBO_CACHE_DIR: .turbo/ios
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup
uses: ./.github/actions/setup
+ - name: Generate nitrogen code
+ run: yarn nitrogen
+
- name: Cache turborepo for iOS
- uses: actions/cache@v3
+ uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
with:
path: ${{ env.TURBO_CACHE_DIR }}
key: ${{ runner.os }}-turborepo-ios-${{ hashFiles('yarn.lock') }}
@@ -133,24 +140,19 @@ jobs:
echo "turbo_cache_hit=1" >> $GITHUB_ENV
fi
- - name: Cache cocoapods
+ - name: Use appropriate Xcode version
if: env.turbo_cache_hit != 1
- id: cocoapods-cache
- uses: actions/cache@v3
+ uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
- path: |
- **/ios/Pods
- key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
- restore-keys: |
- ${{ runner.os }}-cocoapods-
+ xcode-version: ${{ env.XCODE_VERSION }}
- name: Install cocoapods
if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
- cd example/ios
- pod install
- env:
- NO_FLIPPER: 1
+ cd example
+ bundle install
+ bundle exec pod repo update --verbose
+ bundle exec pod install --project-directory=ios
- name: Build example for iOS
run: |
diff --git a/.gitignore b/.gitignore
index 148db35..77eda3f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,7 +28,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
-.xcode.env.local
+**/.xcode.env.local
# Android/IJ
#
@@ -81,3 +81,8 @@ lib/
# React Native Codegen
ios/generated
android/generated
+
+# React Native Nitro Modules
+nitrogen/
+
+libs/generated
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..07c82da
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "libs/miniaudio"]
+ path = libs/miniaudio
+ url = https://github.com/mackron/miniaudio.git
diff --git a/.java-version b/.java-version
deleted file mode 100644
index 98d9bcb..0000000
--- a/.java-version
+++ /dev/null
@@ -1 +0,0 @@
-17
diff --git a/.nvmrc b/.nvmrc
index 3f430af..5f53e87 100644
--- a/.nvmrc
+++ b/.nvmrc
@@ -1 +1 @@
-v18
+v20.19.0
diff --git a/AudioAnalyzer.podspec b/AudioAnalyzer.podspec
new file mode 100644
index 0000000..ad4e5bd
--- /dev/null
+++ b/AudioAnalyzer.podspec
@@ -0,0 +1,59 @@
+require "json"
+
+package = JSON.parse(File.read(File.join(__dir__, "package.json")))
+
+# Run the miniaudio preparation script
+script_path = File.join(__dir__, "scripts", "prepare_miniaudio.rb")
+if File.exist?(script_path)
+ system("ruby #{script_path}")
+else
+ puts "Warning: Miniaudio preparation script not found at #{script_path}"
+end
+
+Pod::Spec.new do |s|
+ s.name = "AudioAnalyzer"
+ s.version = package["version"]
+ s.summary = package["description"]
+ s.homepage = package["homepage"]
+ s.license = package["license"]
+ s.authors = package["author"]
+
+ s.platforms = { :ios => min_ios_version_supported }
+ s.source = { :git => "https://github.com/exzos28/react-native-audio-analyzer.git", :tag => "#{s.version}" }
+
+ # Use pod_target_xcconfig instead of compiler_flags
+ s.pod_target_xcconfig = {
+ # C++ compiler flags for miniaudio on iOS
+ 'GCC_PREPROCESSOR_DEFINITIONS' => 'MA_NO_PTHREAD_IN_HEADER=1',
+ 'OTHER_CFLAGS' => '-DMA_NO_PTHREAD_IN_HEADER',
+ 'OTHER_LDFLAGS' => '-lm -lpthread',
+ 'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
+ 'CLANG_CXX_LIBRARY' => 'libstdc++'
+ }
+
+ # Required frameworks for iOS audio (Core Audio)
+ s.frameworks = [
+ 'AVFoundation'
+ ]
+
+ s.source_files = [
+ # Implementation (Swift)
+ "ios/**/*.{swift}",
+ # Autolinking/Registration (Objective-C++)
+ "ios/**/*.{m,mm}",
+ # Miniaudio implementation - compile as Objective-C (generated)
+ "libs/generated/miniaudio.m",
+ "libs/miniaudio/miniaudio.h",
+ # Implementation (C++ objects)
+ "cpp/**/*.{hpp,cpp}",
+ ]
+ s.public_header_files = "libs/miniaudio/miniaudio.h"
+
+ s.dependency 'React-jsi'
+ s.dependency 'React-callinvoker'
+
+ load 'nitrogen/generated/ios/AudioAnalyzer+autolinking.rb'
+ add_nitrogen_files(s)
+
+ install_modules_dependencies(s)
+end
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 78683cb..26db22c 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -19,6 +19,21 @@ yarn
> Since the project relies on Yarn workspaces, you cannot use [`npm`](https://github.com/npm/cli) for development.
+This project uses Nitro Modules. If you're not familiar with how Nitro works, make sure to check the [Nitro Modules Docs](https://nitro.margelo.com/).
+
+You need to run [Nitrogen](https://nitro.margelo.com/docs/nitrogen) to generate the boilerplate code required for this project. The example app will not build without this step.
+
+Run **Nitrogen** in following cases:
+
+- When you make changes to any `*.nitro.ts` files.
+- When running the project for the first time (since the generated files are not committed to the repository).
+
+To invoke **Nitrogen**, use the following command:
+
+```sh
+yarn nitrogen
+```
+
The [example app](/example/) demonstrates usage of the library. You need to run it to test any changes you make.
It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.
@@ -47,6 +62,14 @@ To run the example app on iOS:
yarn example ios
```
+To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:
+
+```sh
+Running "AudioAnalyzerExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}
+```
+
+Note the `"fabric":true` and `"concurrentRoot":true` properties.
+
Make sure your code passes TypeScript and ESLint. Run the following to verify:
```sh
diff --git a/LICENSE b/LICENSE
index e498e4c..c3ec4f7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2024 exzos
+Copyright (c) 2025 exzos
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
diff --git a/README.md b/README.md
index 2085f55..7896567 100644
--- a/README.md
+++ b/README.md
@@ -8,34 +8,203 @@ This package offers robust tools that enable developers to process audio files e
With this library, unleash creativity by generating captivating audio waveforms from your audio tracks, providing an engaging visual representation of sound.
-
-
-
+
-## Usage 🎶
+## Features ✨
-Usage example you can [find here](example/src/App.tsx)
+- **Audio Analysis**: Easily analyze audio tracks to obtain amplitude data for visualization or analysis purposes
+- **Flexible Visualization**: Visualize amplitude data in a customizable manner, allowing developers to create diverse representations based on audio characteristics, including stunning audio waveforms
+- **Sample and Scale Data**: Utilize functions to sample and scale amplitude data, providing more granular control over visualization output
+- **Platform Compatibility**: Compatible with both Android and iOS platforms, ensuring a consistent experience across devices
+- **High Performance**: Built with C++ and miniaudio library for optimal performance
+- **TypeScript Support**: Full TypeScript support with comprehensive type definitions
## Installation 🚀
-```sh
-yarn add react-native-audio-analyzer
+```bash
+npm install react-native-audio-analyzer react-native-nitro-modules
+# or
+yarn add react-native-audio-analyzer react-native-nitro-modules
+```
+
+> **Note**: `react-native-nitro-modules` is required as this library relies on [Nitro Modules](https://nitro.margelo.com/).
+
+### iOS Setup
+
+```bash
cd ios && pod install
```
-## Features ✨
-- __Audio Analysis__: Easily analyze audio tracks to obtain amplitude data for visualization or analysis purposes.
+## Usage 🎶
+
+### Basic Usage
+
+```typescript
+import { computeAmplitude } from 'react-native-audio-analyzer';
+
+// Analyze audio file and get amplitude data
+const amplitudeData = computeAmplitude('/path/to/audio.mp3', 1000);
+console.log('Amplitude data:', amplitudeData);
+```
+
+### Creating Audio Waveforms
+
+```typescript
+import React, { useCallback, useEffect, useState } from 'react';
+import { View, StyleSheet, ScrollView } from 'react-native';
+import { computeAmplitude } from 'react-native-audio-analyzer';
+
+export default function AudioWaveform() {
+ const [amplitudeData, setAmplitudeData] = useState([]);
+
+ const analyzeAudio = useCallback(async () => {
+ try {
+ const result = computeAmplitude(
+ '/path/to/your/audio.mp3',
+ 1000 // Number of amplitude samples to generate
+ );
+ setAmplitudeData(result);
+ } catch (error) {
+ console.error('Error analyzing audio:', error);
+ }
+ }, []);
+
+ useEffect(() => {
+ analyzeAudio();
+ }, [analyzeAudio]);
+
+ return (
+
+
+ {amplitudeData.map((amplitude, index) => (
+
+ ))}
+
+
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flexGrow: 1,
+ },
+ waveform: {
+ flex: 1,
+ flexDirection: 'row',
+ alignItems: 'center',
+ columnGap: 1,
+ },
+ bar: {
+ width: 3,
+ backgroundColor: '#007AFF',
+ borderRadius: 1,
+ },
+});
+```
+
+### Advanced Usage
+
+```typescript
+import { computeAmplitude } from 'react-native-audio-analyzer';
+
+// Customize the number of amplitude samples
+const highResolution = computeAmplitude('/audio.mp3', 2000); // More detailed
+const lowResolution = computeAmplitude('/audio.mp3', 100); // Less detailed
+
+// Process the amplitude data for different visualizations
+const normalizedData = highResolution.map(amplitude =>
+ Math.min(amplitude * 100, 1.0) // Normalize to 0-1 range
+);
+
+// Create different visualization styles
+const createWaveform = (data: number[], style: 'bars' | 'line' | 'area') => {
+ switch (style) {
+ case 'bars':
+ return data.map((amp, i) => ({ x: i, y: amp }));
+ case 'line':
+ return data.map((amp, i) => ({ x: i, y: amp }));
+ case 'area':
+ return data.map((amp, i) => ({ x: i, y: amp, height: amp }));
+ }
+};
+```
+
+## API Reference 📚
+
+### `computeAmplitude(filePath: string, outputSampleCount: number): number[]`
+
+Analyzes an audio file and returns an array of amplitude values.
+
+#### Parameters
-- __Flexible Visualization__: Visualize amplitude data in a customizable manner, allowing developers to create diverse representations based on audio characteristics, including stunning audio waveforms.
+- `filePath` (string): Path to the audio file to analyze
+- `outputSampleCount` (number): Number of amplitude samples to generate
-- __Sample and Scale Data__: Utilize functions to sample and scale amplitude data, providing more granular control over visualization output.
+#### Returns
-- __Platform Compatibility__: Compatible with both Android and iOS platforms, ensuring a consistent experience across devices.
+- `number[]`: Array of amplitude values between 0 and 1
+#### Example
+
+```typescript
+const amplitudes = computeAmplitude('/path/to/song.mp3', 500);
+// Returns: [0.1, 0.3, 0.5, 0.2, ...] (500 values)
+```
+
+## Supported Audio Formats 🎼
+
+This library supports various audio formats through the miniaudio library:
+
+- **Lossy**: MP3, AAC, OGG Vorbis, Opus
+- **Lossless**: FLAC, WAV, AIFF
+- **Other**: WMA, M4A, and more
+
+## Performance Considerations ⚡
+
+- The library uses native C++ code for optimal performance
+- Audio processing is done efficiently with minimal memory usage
+- Large audio files are processed in chunks to maintain responsiveness
+- Consider using appropriate `outputSampleCount` values based on your visualization needs
+
+## Platform Support 📱
+
+- ✅ iOS 12.0+
+- ✅ Android API 21+
+- ✅ React Native 0.70+
## Contributing 🤝
-We welcome [contributions](CONTRIBUTING.md)! Learn more about how to contribute to this repository by checking out our contributing guide and development workflow.
+
+We welcome contributions! Please see our [contributing guide](CONTRIBUTING.md) to learn how to contribute to this repository and the development workflow.
+
+### Development Setup
+
+```bash
+# Clone the repository
+git clone https://github.com/exzos28/react-native-audio-analyzer.git
+cd react-native-audio-analyzer
+
+# Install dependencies
+yarn install
+
+# Run the example app
+yarn example
+```
## License 📝
-This project is licensed under the MIT License.
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
+
+## Related Projects 🔗
+
+- [react-native-nitro-modules](https://github.com/margelo/react-native-nitro-modules) - The underlying native module system
+- [miniaudio](https://github.com/mackron/miniaudio) - The audio processing library
+
+---
+
+Made with ❤️ by the React Native community
diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt
index 34b16d0..fca0988 100644
--- a/android/CMakeLists.txt
+++ b/android/CMakeLists.txt
@@ -1,54 +1,44 @@
+project(audioanalyzer)
cmake_minimum_required(VERSION 3.9.0)
-project(simple)
+set(PACKAGE_NAME audioanalyzer)
+set(CMAKE_VERBOSE_MAKEFILE ON)
+set(CMAKE_CXX_STANDARD 20)
+# Miniaudio compilation flags
+add_definitions(-DMA_NO_PTHREAD_IN_HEADER=1)
+set(CACHE_DIR ${CMAKE_SOURCE_DIR}/build)
-set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
-set (FFMPEG_DIR ${BUILD_DIR}/ffmpeg)
-set (FFMPEG_SO_DIR ${FFMPEG_DIR}/ffmpeg-built-6.1)
-set (FFMPEG_ARCH_DIR ${FFMPEG_SO_DIR}/${ANDROID_ABI})
-set (FFMPEG_HEADERS ${FFMPEG_DIR}/ffmpeg-headers-5.1/include)
+file(GLOB_RECURSE CORE_SRC RELATIVE ${CMAKE_SOURCE_DIR} "./src/main/cpp/*.cpp")
+file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "../cpp/*.cpp")
-add_library(simple
- SHARED
- ../cpp/AudioAnalyzer.cpp
- ../cpp/AnalyzerRuntime.cpp
- cpp-adapter.cpp
-)
-
-include_directories(
- ../cpp
- ${FFMPEG_HEADERS}
-)
+# Add miniaudio source
+set(MINIAUDIO_SRC "../libs/miniaudio/miniaudio.c")
-set_target_properties(simple PROPERTIES
- CXX_STANDARD 20
- CXX_STANDARD_REQUIRED ON
- CXX_EXTENSIONS OFF
- POSITION_INDEPENDENT_CODE ON
+add_library(
+ ${PACKAGE_NAME}
+ SHARED
+ ${CORE_SRC}
+ ${SOURCES}
+ ${MINIAUDIO_SRC}
)
-find_package(ReactAndroid REQUIRED CONFIG)
-find_package(fbjni REQUIRED CONFIG)
-
-target_link_libraries(simple
- ReactAndroid::jsi
- ReactAndroid::turbomodulejsijni
- ReactAndroid::react_nativemodule_core
- android
- fbjni::fbjni
-)
+# Add Nitrogen specs :)
+include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/audioanalyzer+autolinking.cmake)
-include_directories(${FFMPEG_ARCH_DIR}/include)
+# Set up local includes
+include_directories("src/main/cpp" "../cpp" "../libs/miniaudio")
-add_library(avcodec SHARED IMPORTED)
-add_library(avformat SHARED IMPORTED)
-add_library(avutil SHARED IMPORTED)
-add_library(swresample SHARED IMPORTED)
+target_include_directories(${PACKAGE_NAME} PRIVATE "${CACHE_DIR}/download-cache")
-set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavcodec.so)
-set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavformat.so)
-set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavutil.so)
-set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libswresample.so)
+find_library(LOG_LIB log)
+find_library(OPENSLES_LIB OpenSLES)
+find_library(ANDROID_LIB android)
-target_link_libraries(simple avcodec avformat avutil swresample log)
+# Link all libraries together
+target_link_libraries(
+ ${PACKAGE_NAME}
+ ${LOG_LIB}
+ ${OPENSLES_LIB}
+ ${ANDROID_LIB}
+)
diff --git a/android/build.gradle b/android/build.gradle
index 3990bf8..4633c63 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,16 +1,7 @@
-def WORKING_DIRECTORY = "ffmpeg"
-
-def SO_SRC_URL = "https://github.com/exzos28/ffmpeg-built/archive/refs/tags/6.1.zip"
-//TODO: Change name
-def ARTIFACT_SO_LOCAL = "ffmpeg-built-6.1"
-
-def HEADER_SRC_URL = "https://github.com/exzos28/ffmpeg-headers/archive/refs/tags/5.1.zip"
-//TODO: Change name
-def ARTIFACT_HEADERS_LOCAL = "ffmpeg-headers-5.1"
-
buildscript {
- // Buildscript is evaluated before everything else so we can't use getExtOrDefault
- def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["AudioAnalyzer_kotlinVersion"]
+ ext.getExtOrDefault = {name ->
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['AudioAnalyzer_' + name]
+ }
repositories {
google()
@@ -18,12 +9,9 @@ buildscript {
}
dependencies {
- classpath "com.android.tools.build:gradle:7.2.1"
+ classpath "com.android.tools.build:gradle:8.7.2"
// noinspection DifferentKotlinGradleVersion
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-
-
- classpath("de.undercouch:gradle-download-task:5.0.1")
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
}
}
@@ -32,55 +20,19 @@ def reactNativeArchitectures() {
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
-def isNewArchitectureEnabled() {
- return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
-}
-
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
-apply plugin: "de.undercouch.download"
-
-
-if (isNewArchitectureEnabled()) {
- apply plugin: "com.facebook.react"
-}
+apply from: '../nitrogen/generated/android/audioanalyzer+autolinking.gradle'
-def resolveBuildType() {
- Gradle gradle = getGradle()
- String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
-
- return tskReqStr.contains('Release') ? 'release' : 'debug'
-}
-
-def getExtOrDefault(name) {
- return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["AudioAnalyzer_" + name]
-}
+apply plugin: "com.facebook.react"
def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["AudioAnalyzer_" + name]).toInteger()
}
-def supportsNamespace() {
- def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
- def major = parsed[0].toInteger()
- def minor = parsed[1].toInteger()
-
- // Namespace support was added in 7.3.0
- return (major == 7 && minor >= 3) || major >= 8
-}
-
android {
- if (supportsNamespace()) {
- namespace "com.audioanalyzer"
+ namespace "com.margelo.nitro.audioanalyzer"
- sourceSets {
- main {
- manifest.srcFile "src/main/AndroidManifestNew.xml"
- }
- }
- }
-
- ndkVersion getExtOrDefault("ndkVersion")
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
defaultConfig {
@@ -89,17 +41,22 @@ android {
externalNativeBuild {
cmake {
- arguments "-DANDROID_STL=c++_shared"
- cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
+ cppFlags "-frtti -fexceptions -Wall -fstack-protector-all"
+ arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
abiFilters (*reactNativeArchitectures())
+
+ buildTypes {
+ debug {
+ cppFlags "-O1 -g"
+ }
+ release {
+ cppFlags "-O2"
+ }
+ }
}
}
}
- buildFeatures {
- prefab true
- }
-
externalNativeBuild {
cmake {
path "CMakeLists.txt"
@@ -107,18 +64,31 @@ android {
}
packagingOptions {
- doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
excludes = [
- "META-INF",
- "META-INF/**",
- "**/libjsi.so",
- "**/libc++_shared.so",
- "**/libreact_nativemodule_core.so",
- "**/libturbomodulejsijni.so",
- "**/libfbjni.so"
+ "META-INF",
+ "META-INF/**",
+ "**/libc++_shared.so",
+ "**/libfbjni.so",
+ "**/libjsi.so",
+ "**/libfolly_json.so",
+ "**/libfolly_runtime.so",
+ "**/libglog.so",
+ "**/libhermes.so",
+ "**/libhermes-executor-debug.so",
+ "**/libhermes_executor.so",
+ "**/libreactnative.so",
+ "**/libreactnativejni.so",
+ "**/libturbomodulejsijni.so",
+ "**/libreact_nativemodule_core.so",
+ "**/libjscexecutor.so"
]
}
+ buildFeatures {
+ buildConfig true
+ prefab true
+ }
+
buildTypes {
release {
minifyEnabled false
@@ -134,36 +104,13 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}
-
- tasks.register('downloadAarFile', Download) {
- src SO_SRC_URL
- onlyIfNewer true
- overwrite false
- dest layout.buildDirectory.file(ARTIFACT_SO_LOCAL)
- }
-
- tasks.register('downloadAndUnzipAarFile', Copy) {
- dependsOn downloadAarFile
- from zipTree(downloadAarFile.dest)
- into layout.buildDirectory.dir(WORKING_DIRECTORY)
- }
-
- tasks.register('downloadHeaders', Download) {
- src HEADER_SRC_URL
- onlyIfNewer true
- overwrite false
- dest layout.buildDirectory.file(ARTIFACT_HEADERS_LOCAL)
- }
-
- tasks.register('downloadAndUnzipHeaders', Copy) {
- dependsOn downloadHeaders
- from zipTree(downloadHeaders.dest)
- into layout.buildDirectory.dir(WORKING_DIRECTORY)
- }
-
- afterEvaluate {
- preBuild.dependsOn downloadAndUnzipAarFile
- preBuild.dependsOn downloadAndUnzipHeaders
+ sourceSets {
+ main {
+ java.srcDirs += [
+ "generated/java",
+ "generated/jni"
+ ]
+ }
}
}
@@ -175,10 +122,8 @@ repositories {
def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
- // For < 0.71, this will be from the local maven repo
- // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
- //noinspection GradleDynamicVersion
- implementation "com.facebook.react:react-native:+"
+ implementation "com.facebook.react:react-android"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
+ implementation project(":react-native-nitro-modules")
}
diff --git a/android/cpp-adapter.cpp b/android/cpp-adapter.cpp
deleted file mode 100644
index 365d17c..0000000
--- a/android/cpp-adapter.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include
-#include
-#include