Skip to content

Upgrade gradle, NDK version, target version, fix permission issues#730

Open
ernestp wants to merge 1 commit into
jiangdongguo:masterfrom
ernestp:feature/make-it-compile-in-2025
Open

Upgrade gradle, NDK version, target version, fix permission issues#730
ernestp wants to merge 1 commit into
jiangdongguo:masterfrom
ernestp:feature/make-it-compile-in-2025

Conversation

@ernestp
Copy link
Copy Markdown

@ernestp ernestp commented Jun 28, 2025

Following changes to make it compile and run under latest Android Studio:

  1. Upgrade gradle scripts
  2. Update obsolete dependencies (only those that was breaking build)
  3. Update NDK version
  4. Update min/target SDK version
  5. Replace jcenter with mavenCentral
  6. Single place to change NDK version
  7. Single place to change min/target SDK version
  8. Upgrade Gradle plugin version
  9. Upgrade Kotlin version
  10. Upgrade Gradle version
  11. Upgrade CMake version
  12. Remove obsolete build tools version
  13. Remove useDeprecatedNdk flag
  14. Fix native code to compile with new NDK
  15. Fixed ACTION_USB_PERMISSION intent to use FLAG_MUTABLE on newer Android
  16. Tried to update x86 targets, but it require updating native libraries with PIC support, so removed x86 for now

@w3ichen
Copy link
Copy Markdown

w3ichen commented Jul 15, 2025

@ernestp were you able to get the app connected to modern usb cameras? I got your updated code to compile and run with the latest Android Studio, but my camera, which I got from Amazon, is not detected.

@ernestp
Copy link
Copy Markdown
Author

ernestp commented Jul 15, 2025

@w3ichen It work with my camera, but I need to restart the app after install and first run. If your camera is working with apk from https://github.com/jiangdongguo/AndroidUSBCamera/tree/master then it should work with this pull request. However issue comes from increasing target SDK version. Try to set target SDK version to 27 as in original repo and check if that is fixes issue for you.

@w3ichen
Copy link
Copy Markdown

w3ichen commented Jul 20, 2025

@ernestp thanks. I'm using your branch with target SDK set to 27. It seems to recognize the camera, but it has 2 issues: no videofeed/preview is showing (just blank screen), and when I click the shutter button, I get an error about unable to write to storage. Have you faced this issues before?
I'm running this on Samsung Galaxy with Android 14, and tried two usb webcams that I plugged in via a usb-A to usb-C dongle.

Thanks for your help!

@ernestp
Copy link
Copy Markdown
Author

ernestp commented Jul 20, 2025

@w3ichen I prepared another PR - #736 and will merge both to my fork. And I guess I will go with the next changes in my own repo as original repo don't seems to be active.

@ernestp
Copy link
Copy Markdown
Author

ernestp commented Jul 21, 2025

@w3ichen Does preview working with APK from original repo? Have you tried new PR?

@OwenChen0911
Copy link
Copy Markdown

@ernestp good job
have you ever met OOM like this?

09-01 04:00:56.950 1113 979 E AndroidRuntime: *** FATAL EXCEPTION IN SYSTEM PROCESS: binder:1113_13
09-01 04:00:56.950 1113 979 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 56 byte allocation with 5275168 free bytes and 5151KB until OOM, target footprint 536870912, growth limit 536870912; giving up on allocation because <1% of heap free after GC.
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.nativeReadString16(Native Method)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readString16NoHelper(Parcel.java:3097)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel$ReadWriteHelper.readString16(Parcel.java:497)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readString16(Parcel.java:3076)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readString(Parcel.java:3066)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableCreatorInternal(Parcel.java:4836)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableInternal(Parcel.java:4766)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableArrayInternal(Parcel.java:4965)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableArray(Parcel.java:4952)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.hardware.usb.UsbDevice$1.createFromParcel(UsbDevice.java:361)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.hardware.usb.UsbDevice$1.createFromParcel(UsbDevice.java:348)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Parcel.readTypedObject(Parcel.java:3947)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.hardware.usb.IUsbManager$Stub.onTransact(IUsbManager.java:591)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Binder.execTransactInternal(Binder.java:1280)
09-01 04:00:56.950 1113 979 E AndroidRuntime: at android.os.Binder.execTransact(Binder.java:1244)
09-01 04:01:05.377 1113 979 E AndroidRuntime: OutOfMemoryError IN SYSTEM PROCESS: Already dump hprof!
09-01 04:01:05.377 1113 979 E AndroidRuntime: java.lang.OutOfMemoryError: Failed to allocate a 56 byte allocation with 5275168 free bytes and 5151KB until OOM, target footprint 536870912, growth limit 536870912; giving up on allocation because <1% of heap free after GC.
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.nativeReadString16(Native Method)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readString16NoHelper(Parcel.java:3097)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel$ReadWriteHelper.readString16(Parcel.java:497)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readString16(Parcel.java:3076)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readString(Parcel.java:3066)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableCreatorInternal(Parcel.java:4836)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableInternal(Parcel.java:4766)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableArrayInternal(Parcel.java:4965)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readParcelableArray(Parcel.java:4952)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.hardware.usb.UsbDevice$1.createFromParcel(UsbDevice.java:361)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.hardware.usb.UsbDevice$1.createFromParcel(UsbDevice.java:348)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Parcel.readTypedObject(Parcel.java:3947)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.hardware.usb.IUsbManager$Stub.onTransact(IUsbManager.java:591)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Binder.execTransactInternal(Binder.java:1280)
09-01 04:01:05.377 1113 979 E AndroidRuntime: at android.os.Binder.execTransact(Binder.java:1244)
09-01 04:01:05.377 1113 1113 W Looper : Slow delivery took 4466ms main h=android.os.Handler c=com.android.internal.os.BinderCallsStats$1@825bfb2 m=0
09-01 04:01:05.379 1113 979 I DropBoxManagerService: add tag=system_server_crash isTagEnabled=true flags=0x2
09-01 04:01:05.380 1113 1113 W Looper : Drained
09-01 04:01:05.380 1113 1210 E PackageManager: Missing permissions state for com.android.systemui and user -1
09-01 04:01:10.889 32391 32452 E AndroidRuntime: FATAL EXCEPTION: USBMonitor

@HanselLi
Copy link
Copy Markdown

HanselLi commented Jan 22, 2026

@w3ichen i don't know whether you had solved or not , i encountered the same issue, and now i found the solution.

  1. about the storage permission ,just modify RenderManager , create dir of /sdcard/DCIM/Camera if not exists firstly
        "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)}/Camera".let {
            if (!File(it).exists()) {
                File(it).mkdirs()
            }
            it
        }
    }

Also , i met another issue about ndk compile , follow @ernestp Upgrade gradle, NDK version, target version, fix permission issues RP , that's helpful . But i met ndkBuild task invoke twice that makes gradle ndk compile failed . modify libuvc.gradle as below will solve . do not depends on JavaCompile which is the reason that makes ndk task invoke twice . reigister before prebuild works

//tasks.withType(JavaCompile) {
//	compileTask -> compileTask.dependsOn ndkBuild
//}

preBuild.dependsOn("ndkBuild")

String getNdkBuildPath() {
	Properties properties = new Properties()
	properties.load(project.rootProject.file('local.properties').newDataInputStream())
	def sdkBuildingDir = properties.getProperty("sdk.dir")
	def ndkBuildingDir = sdkBuildingDir + "/ndk/" + rootProject.ext.ndkVersion
	def ndkBuildPath = ndkBuildingDir
	println("ndk path ================: $ndkBuildingDir")
	if (Os.isFamily(Os.FAMILY_WINDOWS)) {
		ndkBuildPath = ndkBuildingDir + '/ndk-build.cmd'
	} else {
		ndkBuildPath = ndkBuildingDir + '/ndk-build'
	}
	return ndkBuildPath
}


tasks.register("ndkBuild", Exec) {
	commandLine ndkBuildPath, 'V=1' , '-j8', '-C', file('src/main').absolutePath
}

//task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
//	println('executing ndkBuild')
//	println "NDK BUILD CWD = " + file('src/main').absolutePath
//	def ndkBuildPath = getNdkBuildPath();
//	commandLine ndkBuildPath, 'V=1' , '-j8', '-C', file('src/main').absolutePath
//}

@w3ichen
Copy link
Copy Markdown

w3ichen commented Jan 22, 2026

Thanks @HanselLi, I realized that the USB camera worked with my newer Android phone and not my old one, so I switched to my other phone instead. But I appreciate the help!

@ernestp
Copy link
Copy Markdown
Author

ernestp commented Jan 25, 2026

Thanks for the discussion here.

Since this repository does not appear to be actively maintained anymore, I’ve continued development and maintenance independently at:
https://github.com/ernestp/AndroidUSBCamera

Please feel free to check the current state of the code there and file issues or contribute if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants