Skip to content

Commit 8e185ae

Browse files
committed
fix: use github and cocoapods to download ffmpeg builds
1 parent b475f59 commit 8e185ae

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

android/CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ project(react-native-audio-analyzer)
44
set(CMAKE_VERBOSE_MAKEFILE ON)
55
set(CMAKE_CXX_STANDARD 11)
66

7+
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
8+
set (FFMPEG_DIR ${BUILD_DIR}/ffmpeg)
9+
set (FFMPEG_SO_DIR ${FFMPEG_DIR}/ffmpeg-built-6.1)
10+
set (FFMPEG_ARCH_DIR ${FFMPEG_SO_DIR}/${ANDROID_ABI})
11+
set (FFMPEG_HEADERS ${FFMPEG_DIR}/ffmpeg-headers-5.1/include)
12+
713
add_library(cpp
814
SHARED
915
../cpp/react-native-audio-analyzer.cpp
@@ -12,11 +18,9 @@ add_library(cpp
1218

1319
include_directories(
1420
../cpp
21+
${FFMPEG_HEADERS}
1522
)
1623

17-
set(FFMPEG_DIR ${CMAKE_SOURCE_DIR}/../ffmpeg/android)
18-
19-
set(FFMPEG_ARCH_DIR ${FFMPEG_DIR}/${ANDROID_ABI}/ffmpeg)
2024

2125
message(STATUS "FFMPEG_ARCH_DIR: ${FFMPEG_ARCH_DIR}")
2226

@@ -32,9 +36,9 @@ add_library(avformat SHARED IMPORTED)
3236
add_library(avutil SHARED IMPORTED)
3337
add_library(swresample SHARED IMPORTED)
3438

35-
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/lib/libavcodec.so)
36-
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/lib/libavformat.so)
37-
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/lib/libavutil.so)
38-
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/lib/libswresample.so)
39+
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavcodec.so)
40+
set_target_properties(avformat PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavformat.so)
41+
set_target_properties(avutil PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libavutil.so)
42+
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${FFMPEG_ARCH_DIR}/libswresample.so)
3943

4044
target_link_libraries(cpp avcodec avformat avutil swresample log)

android/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
def WORKING_DIRECTORY = "ffmpeg"
2+
3+
def SO_SRC_URL = "https://github.com/exzos28/ffmpeg-built/archive/refs/tags/6.1.zip"
4+
//TODO: Change name
5+
def ARTIFACT_SO_LOCAL = "ffmpeg-built-6.1"
6+
7+
def HEADER_SRC_URL = "https://github.com/exzos28/ffmpeg-headers/archive/refs/tags/5.1.zip"
8+
//TODO: Change name
9+
def ARTIFACT_HEADERS_LOCAL = "ffmpeg-headers-5.1"
10+
111
buildscript {
212
repositories {
313
google()
@@ -6,6 +16,7 @@ buildscript {
616

717
dependencies {
818
classpath "com.android.tools.build:gradle:7.2.1"
19+
classpath "de.undercouch:gradle-download-task:5.0.1"
920
}
1021
}
1122

@@ -14,6 +25,7 @@ def isNewArchitectureEnabled() {
1425
}
1526

1627
apply plugin: "com.android.library"
28+
apply plugin: "de.undercouch.download"
1729

1830
if (isNewArchitectureEnabled()) {
1931
apply plugin: "com.facebook.react"
@@ -82,6 +94,37 @@ android {
8294
sourceCompatibility JavaVersion.VERSION_1_8
8395
targetCompatibility JavaVersion.VERSION_1_8
8496
}
97+
98+
tasks.register('downloadAarFile', Download) {
99+
src SO_SRC_URL
100+
onlyIfNewer true
101+
overwrite false
102+
dest layout.buildDirectory.file(ARTIFACT_SO_LOCAL)
103+
}
104+
105+
tasks.register('downloadAndUnzipAarFile', Copy) {
106+
dependsOn downloadAarFile
107+
from zipTree(downloadAarFile.dest)
108+
into layout.buildDirectory.dir(WORKING_DIRECTORY)
109+
}
110+
111+
tasks.register('downloadHeaders', Download) {
112+
src HEADER_SRC_URL
113+
onlyIfNewer true
114+
overwrite false
115+
dest layout.buildDirectory.file(ARTIFACT_HEADERS_LOCAL)
116+
}
117+
118+
tasks.register('downloadAndUnzipHeaders', Copy) {
119+
dependsOn downloadHeaders
120+
from zipTree(downloadHeaders.dest)
121+
into layout.buildDirectory.dir(WORKING_DIRECTORY)
122+
}
123+
124+
afterEvaluate {
125+
preBuild.dependsOn downloadAndUnzipAarFile
126+
preBuild.dependsOn downloadAndUnzipHeaders
127+
}
85128
}
86129

87130
repositories {

example/ios/Podfile.lock

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PODS:
1010
- React-Core (= 0.72.6)
1111
- React-jsi (= 0.72.6)
1212
- ReactCommon/turbomodule/core (= 0.72.6)
13+
- ffmpeg-kit-ios-audio (5.1)
1314
- Flipper (0.182.0):
1415
- Flipper-Folly (~> 2.6)
1516
- Flipper-Boost-iOSX (1.76.0.1.11)
@@ -375,7 +376,8 @@ PODS:
375376
- React-jsinspector (0.72.6)
376377
- React-logger (0.72.6):
377378
- glog
378-
- react-native-audio-analyzer (0.1.0):
379+
- react-native-audio-analyzer (0.1.4):
380+
- ffmpeg-kit-ios-audio (= 5.1)
379381
- RCT-Folly (= 2021.07.22.00)
380382
- React-Core
381383
- React-NativeModulesApple (0.72.6):
@@ -562,6 +564,7 @@ DEPENDENCIES:
562564
SPEC REPOS:
563565
trunk:
564566
- CocoaAsyncSocket
567+
- ffmpeg-kit-ios-audio
565568
- Flipper
566569
- Flipper-Boost-iOSX
567570
- Flipper-DoubleConversion
@@ -665,6 +668,7 @@ SPEC CHECKSUMS:
665668
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
666669
FBLazyVector: 748c0ef74f2bf4b36cfcccf37916806940a64c32
667670
FBReactNativeSpec: 966f29e4e697de53a3b366355e8f57375c856ad9
671+
ffmpeg-kit-ios-audio: 6eaf5a3c4249b767328502747a08bfd901a86d3d
668672
Flipper: 6edb735e6c3e332975d1b17956bcc584eccf5818
669673
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
670674
Flipper-DoubleConversion: 2dc99b02f658daf147069aad9dbd29d8feb06d30
@@ -693,7 +697,7 @@ SPEC CHECKSUMS:
693697
React-jsiexecutor: 3bf18ff7cb03cd8dfdce08fbbc0d15058c1d71ae
694698
React-jsinspector: 194e32c6aab382d88713ad3dd0025c5f5c4ee072
695699
React-logger: cebf22b6cf43434e471dc561e5911b40ac01d289
696-
react-native-audio-analyzer: a1b1d14ea3139da282ddf3c8d94608b4ba4fcd91
700+
react-native-audio-analyzer: ece0398aa8d33fb066efdb7ad73debf034a846f7
697701
React-NativeModulesApple: 02e35e9a51e10c6422f04f5e4076a7c02243fff2
698702
React-perflogger: e3596db7e753f51766bceadc061936ef1472edc3
699703
React-RCTActionSheet: 17ab132c748b4471012abbcdcf5befe860660485

react-native-audio-analyzer.podspec

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ Pod::Spec.new do |s|
1616

1717
s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
1818

19-
s.vendored_frameworks = 'ffmpeg/ios/*.xcframework'
20-
s.public_header_files = 'ffmpeg/ios/*.xcframework/**/Headers/*.h'
19+
s.dependency "ffmpeg-kit-ios-audio", "5.1"
2120

22-
2321
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
2422
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
2523
if respond_to?(:install_modules_dependencies, true)
2624
install_modules_dependencies(s)
2725
else
2826
s.dependency "React-Core"
2927

28+
3029
# Don't install the dependencies when we run `pod install` in the old architecture.
3130
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
3231
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
@@ -41,5 +40,5 @@ Pod::Spec.new do |s|
4140
s.dependency "RCTTypeSafety"
4241
s.dependency "ReactCommon/turbomodule/core"
4342
end
44-
end
43+
end
4544
end

0 commit comments

Comments
 (0)