NativeScript / NativeScript/plugins

[imagepicker] Exception if built in --release mode: `Error: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/documentfile/provider/DocumentFile;`

Đang mở
#554 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
TypeScript
Star
206
Fork
123
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
1

Mô tả

Hello,

Issue

I have updated Imagepicker on its latest version (3.0.0 / 3.0.1). It worked well in dev mode, but when built with the --release flag, it cease to work.

I patched webpack to re-enable logs in release mode (drop_console: false), and get this one.

  • Code:
    const context = Imagepicker.create({
      mode: 'multiple',
    });

    context
      .authorize()
      .then(() => {
        return context.present();
      })
      .then((selection) => { … })
      .catch(function (e: Error) {
        console.error('on select image', e.toString(), e.stack, e.cause);
      });
  • Log:
JS: CONSOLE ERROR: on select image Error: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/documentfile/provider/DocumentFile; getOrSetHelper(file:///data/data/appid/files/app/vendor.js:2:118868)
JS: 	at getFile(file:///data/data/appid/files/app/vendor.js:2:128579)
JS: 	at fromPath(file:///data/data/appid/files/app/vendor.js:2:139398)
JS: 	at handle(file:///data/data/appid/files/app/vendor.js:2:840987)
JS: 	at onResult(file:///data/data/appid/files/app/vendor.js:2:842335)
JS: 	at invokeTask(file:///data/data/appid/files/app/vendor.js:2:1240087)
JS: 	at onInvokeTask(file:///data/data/appid/files/app/vendor.js:2:1553242)
JS: 	at invokeTask(file:///data/data/appid/files/app/vendor.js:2:1240008)
JS: 	at runTask(file:///data/data/appid/files/app/vendor.js:2:1235405)
JS: 	at invokeTask(file:///data/data/appid/files/app/vendor.js:2:1241184)
JS: 	at ZoneTask.i.useG.invoke(file:///data/data/appid/files/app/vendor.js:...

Investigation

So I have extracted and compared the 2 produced APK. Here are some differences that looks suspicious to me in the META-INF directory.

  • Files that does not appear in --release
androidx.cardview_cardview.version
androidx.coordinatorlayout_coordinatorlayout.version
androidx.documentfile_documentfile.version                     # <-- at least this one seems missing for bad reasons
androidx.dynamicanimation_dynamicanimation.version
androidx.legacy_legacy-support-core-utils.version
androidx.localbroadcastmanager_localbroadcastmanager.version
androidx.print_print.version
com.google.android.material_material.version

(These files does not have corresponding entries in MANIFEST.MF.)

  • For files that exists in both side, versions does not match

androidx.customview_customview.version has content 1.1.0 in "dev" and 1.0.0 in "release".
androidx.drawerlayout_drawerlayout.version has content 1.1.1 in "dev" and 1.0.0 in "release".

Other informations

Here are some other informations about my config:

package.json extracts

    "@nativescript/core": "~8.6.1",

    "@nativescript/android": "~8.6.2",
    "@nativescript/types": "~8.6.1",
    "@nativescript/webpack": "~5.0.18",

app.gradle

android {
  compileSdkVersion 33
  defaultConfig {
    minSdkVersion 21
    targetSdkVersion 33
    generatedDensities = []
  }
  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

AndroidManifest.xml extracts

	<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
	<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
	<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" tools:replace="android:maxSdkVersion" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" tools:replace="android:maxSdkVersion" />

	<application
		android:name="com.tns.NativeScriptApplication"
		android:allowBackup="true"
…
		android:requestLegacyExternalStorage="true">

(I first thought it was a permission problem, that's why I have here the old *_EXTERNAL_STORAGE and requestLegacyExternalStorage but I don't think it changed anything. I should probably just revert this!)

Question

I don't really know how these files are generated and what I should try to go forward at this point. Any help appreciated! :-)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với flow authorize/present của Imagepicker và so sánh nội dung META-INF của các APK dev và release, đặc biệt là androidx.documentfile_documentfile.version. Kiểm tra các phiên bản trong package.json, các cài đặt Android trong app.gradle và AndroidManifest.xml; hoàn tất khi đã xác định và sửa cách đóng gói dependency chỉ xảy ra ở release để DocumentFile được resolve.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, typescript, webpack
Lĩnh vực
build-system, mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.