Skip to content

Commit

Permalink
feat(android): add error handling for Kotlin version (#4018)
Browse files Browse the repository at this point in the history
* feat(android): add error handling for Kotlin version mismatch

* fix: lint error

* refactor: use variables from gradle file

* chore: downgrade required Kotlin version

* refactor: check Kotlin version

* refactor: kotlin variables in build.gradle

* refactor: kotlin variables in build.gradle

* chore(doc): update document

* chore: add dependency to build.gradle for a specific version of react-native

* fix: remove additional dependency
  • Loading branch information
seyedmostafahasani authored Jul 24, 2024
1 parent adbd06e commit 6189080
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
31 changes: 26 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ apply plugin: 'kotlin-android'

buildscript {
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNVideo_kotlinVersion']
def requiredKotlinVersion = project.properties['RNVideo_kotlinVersion']

def isVersionAtLeast = { version, requiredVersion ->
def (v1, v2) = [version, requiredVersion].collect { it.tokenize('.')*.toInteger() }
for (int i = 0; i < Math.max(v1.size(), v2.size()); i++) {
int val1 = i < v1.size() ? v1[i] : 0
int val2 = i < v2.size() ? v2[i] : 0
if (val1 < val2) {
return false
} else if (val1 > val2) {
return true
}
}
return true
}

repositories {
mavenCentral()
Expand All @@ -13,9 +28,17 @@ buildscript {
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
}

ext {
if (!isVersionAtLeast(kotlin_version, requiredKotlinVersion)) {
throw new GradleException("Kotlin version mismatch: Project is using Kotlin version $kotlin_version, but it must be at least $requiredKotlinVersion. Please update the Kotlin version.")
} else {
println("Kotlin version is correct: $kotlin_version")
}
}
}

// This looks funny but it's necessary to keep backwards compatibility (:
// This looks funny but it's necessary to keep backwards compatibility (:
def safeExtGet(prop) {
return rootProject.ext.has(prop) ?
rootProject.ext.get(prop) : rootProject.ext.has("RNVideo_" + prop) ?
Expand Down Expand Up @@ -184,7 +207,6 @@ repositories {
}

def media3_version = safeExtGet('media3Version')
def kotlin_version = safeExtGet('kotlinVersion')
def androidxCore_version = safeExtGet('androidxCoreVersion')
def androidxActivity_version = safeExtGet('androidxActivityVersion')

Expand Down Expand Up @@ -239,7 +261,7 @@ dependencies {
implementation "androidx.media3:media3-exoplayer-rtsp:$media3_version"
}
}

// For ad insertion using the Interactive Media Ads SDK with ExoPlayer
if (ExoplayerDependencies["useExoplayerIMA"]) {
if (media3_buildFromSource) {
Expand Down Expand Up @@ -280,5 +302,4 @@ dependencies {
// Common functionality used across multiple media libraries
implementation "androidx.media3:media3-common:$media3_version"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RNVideo_kotlinVersion=1.7.0
RNVideo_kotlinVersion=1.8.0
RNVideo_minSdkVersion=23
RNVideo_targetSdkVersion=34
RNVideo_compileSdkVersion=34
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ class FullScreenPlayerView(
parent = null
}

private fun getFullscreenIconResource(isFullscreen: Boolean): Int {
return if (isFullscreen) {
private fun getFullscreenIconResource(isFullscreen: Boolean): Int =
if (isFullscreen) {
androidx.media3.ui.R.drawable.exo_icon_fullscreen_exit
} else {
androidx.media3.ui.R.drawable.exo_icon_fullscreen_enter
}
}

private fun updateFullscreenButton(playerControlView: LegacyPlayerControlView, isFullscreen: Boolean) {
val imageButton = playerControlView.findViewById<ImageButton?>(com.brentvatne.react.R.id.exo_fullscreen)
Expand Down
6 changes: 4 additions & 2 deletions docs/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ $RNVideoUseGoogleIMA=true

## Android

From version >= 6.0.0, your application needs to have kotlin version >= 1.7.0
From version >= 6.0.0, your application needs to have kotlin version >= 1.8.0

```:
buildscript {
...
ext.kotlinVersion = '1.7.0'
ext.kotlinVersion = '1.8.0',
ext.compileSdkVersion = 34
ext.targetSdkVersion = 34
...
}
```
Expand Down

0 comments on commit 6189080

Please sign in to comment.