flutter_rtmppublisher icon indicating copy to clipboard operation
flutter_rtmppublisher copied to clipboard

android kotlin `Expected type mismatch: inferred type is Int? but Int was expected` error

Open bnuby opened this issue 3 years ago • 3 comments

PLEASE HELP

Hi, Is there any got this error?? only have this error when I run the apps on the android. no issue for ios.

Flutter Doctor

[✓] Flutter (Channel unknown, 1.24.0-10.2.pre, on Mac OS X 10.15.7 19H2 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.53.2)
[✓] Connected device (1 available)
// Java Version
openjdk version "1.8.0_242-release"
OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
OpenJDK 64-Bit Server VM (build 25.242-b3-6915495, mixed mode)

// Flutter Version
Flutter 1.24.0-10.2.pre • channel unknown • unknown source
Framework • revision 022b333a08 (4 months ago) • 2020-11-18 11:35:09 -0800
Engine • revision 07c1eed46b
Tools • Dart 2.12.0 (build 2.12.0-29.10.beta)

Error Message

e: /home/XXXXXXXXXXXX/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 inference failed. Expected type mismatch: inferred type is Int? but Int was expected
e: /home/XXXXXXXXXXXX/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, 13): Type inference failed: Cannot infer type parameter V in inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit
None of the following substitutions                                     
receiver: MutableMap<String, Any>  arguments: (String,Any)              
receiver: MutableMap<String, Int?>  arguments: (String,Int?)            
can be applied to                                                       
receiver: HashMap<String, Any>  arguments: (String,Int?)                
                                                                        
e: /home/XXXXXXXXXXXX/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
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':camera_with_rtmp:compileDebugKotlin'.       
> Compilation error. See log for more details                           
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 23s 

bnuby avatar Mar 05 '21 12:03 bnuby

same here

FDhunterz avatar Mar 18 '21 05:03 FDhunterz

same here

+1

Kedar-27 avatar Mar 26 '21 12:03 Kedar-27

Same, the project is not being built. Output:

Running Gradle task 'assembleDebug'...
e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\AppVideoEncoder.kt: (221, 59): Type mismatch: inferred type is ByteBuffer? but ByteBuffer was expected

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\AppVideoEncoder.kt: (430, 23): Type mismatch: inferred type is ByteBuffer? but ByteBuffer was expected

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (42, 1): Class 'Camera' is not abstract and does not implement abstract member public abstract fun surfaceChanged(@NonNull p0: SurfaceHolder, p1: Int, p2: Int, p3: Int): Unit defined in android.view.SurfaceHolder.Callback

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (96, 45): Type inference failed. Expected type mismatch: inferred type is Int? but Int was expected

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (856, 5): 'surfaceChanged' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (863, 5): 'surfaceDestroyed' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (866, 5): 'surfaceCreated' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (25, 1): Class 'CameraNativeView' is not abstract and does not implement abstract member public abstract fun surfaceChanged(@NonNull p0: SurfaceHolder, p1: Int, p2: Int, p3: Int): Unit defined in android.view.SurfaceHolder.Callback

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (87, 5): 'surfaceChanged' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (91, 5): 'surfaceDestroyed' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraUtils.kt: (51, 13): Type inference failed: Cannot infer type parameter V in inline operator fun <K, V> MutableMap<K, V>.set(key: K, value: V): Unit

None of the following substitutions

receiver: MutableMap<String, Any>  arguments: (String,Any)

receiver: MutableMap<String, Int?>  arguments: (String,Int?)

can be applied to

receiver: HashMap<String, Any>  arguments: (String,Int?)





FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':rtmp_publisher:compileDebugKotlin'.

> Compilation error. See log for more details

The problem is partially solved: https://github.com/pinkfish/flutter_rtmppublisher/issues/36

But still the following problems remain:

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (42, 1): Class 'Camera' is not abstract and does not implement abstract member public abstract fun surfaceChanged(@NonNull p0: SurfaceHolder, p1: Int, p2: Int, p3: Int): Unit defined in android.view.SurfaceHolder.Callback

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (856, 5): 'surfaceChanged' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (863, 5): 'surfaceDestroyed' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\Camera.kt: (866, 5): 'surfaceCreated' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (25, 1): Class 'CameraNativeView' is not abstract and does not implement abstract member public abstract fun surfaceChanged(@NonNull p0: SurfaceHolder, p1: Int, p2: Int, p3: Int): Unit defined in android.view.SurfaceHolder.Callback

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (87, 5): 'surfaceChanged' overrides nothing

e: \Pub\Cache\hosted\pub.dartlang.org\rtmp_publisher-0.3.7\android\src\main\kotlin\com\app\rtmp_publisher\CameraNativeView.kt: (91, 5): 'surfaceDestroyed' overrides nothing

This seems to be a version compatibility issue, it is solved like this:

Camera.kt

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
    // implement here ...
}

override fun surfaceDestroyed(holder: SurfaceHolder) {}
override fun surfaceCreated(holder: SurfaceHolder) {}

CameraNativeView.kt

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
     Log.d("CameraNativeView", "surfaceChanged $width $height")
}

override fun surfaceDestroyed(holder: SurfaceHolder) {
     Log.d("CameraNativeView", "surfaceDestroyed")
}

So I was able to build the project and successfully start streaming to the rtmp server. I hope this will be fixed

zikwall avatar Mar 28 '21 15:03 zikwall