pinkfish / flutter_rtmppublisher

Publisher to rtmp using the camera plugin as a basis to do all the basic camera/record management.
BSD 3-Clause "New" or "Revised" License
95 stars 121 forks source link

camera_with_rtmp: android build failure due to type mismatch #36

Closed colin-hanbury closed 3 years ago

colin-hanbury commented 3 years ago

I've been unable to run on an android device due to the following failure during the gradle build:

FAILURE: Build failed with an exception.

...\flutter.pub-cache\hosted\pub.dartlang.org\camera_with_rtmp-0.3.2\android\src\main\kotlin\com\whelksoft\camera_with_rtmp\Camera.kt: (682, 29): Type mismatch: inferred type is Int? but Int was expected ...\flutter.pub-cache\hosted\pub.dartlang.org\camera_with_rtmp-0.3.2\android\src\main\kotlin\com\whelksoft\camera_with_rtmp\Camera.kt: (682, 45): Type mismatch: inferred type is Int? but Int was expected ...\flutter.pub-cache\hosted\pub.dartlang.org\camera_with_rtmp-0.3.2\android\src\main\kotlin\com\whelksoft\camera_with_rtmp\CameraUtils.kt: (51, 44): Type mismatch: inferred type is Int? but TypeVariable(V) was expected ...\flutter.pub-cache\hosted\pub.dartlang.org\camera_with_rtmp-0.3.2\android\src\main\kotlin\com\whelksoft\camera_with_rtmp\VideoEncoder.kt: (427, 23): Type mismatch: inferred type is ByteBuffer? but ByteBuffer was expected

snippet from pubspec.yaml:

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  google_maps_flutter: ^0.5.27+3
  flutter_material_pickers: ^1.8.0
  video_player: ^0.11.1+2
  camera_with_rtmp: ^0.3.2

build.gradle:

buildscript {
    ext.kotlin_version = '1.4.0'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app\build.gradle:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 29

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "com.example.exampleapp"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }

    packagingOptions {
       exclude 'project.clj'
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

apply plugin: 'com.google.gms.google-services'

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel master, 1.24.0-4.0.pre.107, on Microsoft Windows [√] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [√] Android Studio (version 4.1.0) [√] IntelliJ IDEA Community Edition (version 2019.3) [√] VS Code (version 1.47.3) [√] Connected device (1 available)

• No issues found!

colin-hanbury commented 3 years ago

@pinkfish I have found a fix for this issue. Adding the not-null assertion operator to the following prevents the type mismatch errors from occurring:

android\src\main\kotlin\com\whelksoft\camera_with_rtmp\Camera.kt line 682:

sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION)!!

android\src\main\kotlin\com\whelksoft\camera_with_rtmp\CameraUtils.kt line 51:

details["sensorOrientation"] = sensorOrientation!!

android\src\main\kotlin\com\whelksoft\camera_with_rtmp\VideoEncoder.kt line 427:

processOutput(byteBuffer!!, mediaCodec, outBufferIndex, bufferInfo)

android\src\main\kotlin\com\whelksoft\camera_with_rtmp\VideoEncoder.kt line 218:

val byteBufferList = extractVpsSpsPpsFromH265(mediaFormat.getByteBuffer("csd-0")!!)