【发布时间】:2019-08-26 09:17:57
【问题描述】:
我正在使用 NativeScript 6.0 和 Angular 8.0 并尝试使用 nativescript-http-formdata 插件并不断遇到依赖问题;
LOG from device Galaxy S8: Error: java.lang.Exception: Failed resolving method create on class okhttp3.RequestBody
完全错误;
LOG from device Galaxy S8: Taken picture
LOG from device Galaxy S8: Gallery: /storage/emulated/0/DCIM/Camera/NSIMG_20190821_10221.jpg
LOG from device Galaxy S8: Saved: /data/user/0/org.nativescript.preview/files/NSIMG_20190821_10221_thumbnail.jpg
LOG from device Galaxy S8: com.tns.Runtime.resolveMethodOverload(Runtime.java:1201)
LOG from device Galaxy S8: com.tns.Runtime.callJSMethodNative(Native Method)
LOG from device Galaxy S8: com.tns.Runtime.callJSMethodImpl(Runtime.java:1122)
LOG from device Galaxy S8: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1242)
LOG from device Galaxy S8: com.tns.Runtime.callJSMethod(Runtime.java:1109)
LOG from device Galaxy S8: com.tns.Runtime.callJSMethod(Runtime.java:1089)
LOG from device Galaxy S8: FILE: /data/user/0/org.nativescript.preview/files/NSIMG_20190821_10221_thumbnail.jpg
LOG from device Galaxy S8: Image saved successfully!
LOG from device Galaxy S8: Error: java.lang.Exception: Failed resolving method create on class okhttp3.RequestBody
LOG from device Galaxy S8: com.tns.Runtime.callJSMethod(Runtime.java:1081)
LOG from device Galaxy S8: com.tns.NativeScriptActivity.onActivityResult(NativeScriptActivity.java:54)
LOG from device Galaxy S8: android.app.Activity.dispatchActivityResult(Activity.java:7282)
LOG from device Galaxy S8: android.app.ActivityThread.deliverResults(ActivityThread.java:4516)
LOG from device Galaxy S8: android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
LOG from device Galaxy S8: android.app.ActivityThread.-wrap22(ActivityThread.java)
LOG from device Galaxy S8: android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
LOG from device Galaxy S8: android.os.Handler.dispatchMessage(Handler.java:102)
LOG from device Galaxy S8: android.os.Looper.loop(Looper.java:154)
LOG from device Galaxy S8: android.app...
我正在使用 nativescript-http-formdata 插件发送照片
async sendPicture(filepath, imageAsset) {
var url = "http://localhost:9000/images/upload";
var name = filepath.substr(filepath.lastIndexOf("/") + 1);
// Get bitmap of file
const imageAndroidBitmap = android.graphics.BitmapFactory.decodeFile(filepath);
// Prepare the formdata
let fd = new TNSHttpFormData();
let param: TNSHttpFormDataParam = {
data: imageAndroidBitmap,
contentType: 'image/jpeg',
fileName: 'test.jpg',
parameterName: 'file1'
};
let params = [];
params.push(param);
try {
const response: TNSHttpFormDataResponse = await fd.post(url, params, {
headers: {}
});
console.log(response);
} catch (e) {
console.log(e);
}
}
我不知道如何在 NativeScript 中安装 okhttp3 依赖项。
到目前为止我已经尝试过什么
- 是否进行了“tns 更新”以防我的包过期。
- 有人说安装nativescript-https满足okhttp3依赖问题
- 安装了 nativescript-okhttp,因为它看起来像我缺少的插件。
更新:向 app.gradle 添加依赖项
在 /App_Resources/Android/app.gradle 中
// Add your native dependencies here:
// Uncomment to add recyclerview-v7 dependency
dependencies {
// implementation 'com.android.support:recyclerview-v7:+'
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.10.0'
}
// If you want to add something to be applied before applying plugins' include.gradle files
// e.g. project.ext.googlePlayServicesVersion = "15.0.1"
// create a file named before-plugins.gradle in the current directory and place it there
android {
defaultConfig {
minSdkVersion 17
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
然后我重新开始预览
tns preview
仍然收到完全相同的错误消息。
更新:使用 nativescript-http-formdata 的 6.0 分支
克隆仓库
cd ~/code/nativescript
git clone https://github.com/dotnetdreamer/nativescript-http-formdata.git
获取 6.0 分支
cd nativescript-http-formdata
git co 6.0
安装插件目录
cd ~/code/AssetManagementPrototype
tns plugin install /home/map7/code/nativescript/nativescript-http-formdata/src
在模拟器中运行
tns run android --device emulator-5554
错误;
ERROR in /home/map7/code/nativescript/nativescript-http-formdata/src/TNSHttpFormData.ts
Module build failed (from ../node_modules/@ngtools/webpack/src/index.js):
Error: /home/map7/code/nativescript/nativescript-http-formdata/src/TNSHttpFormData.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
at NativeScriptAngularCompilerPlugin.getCompiledFile (/home/map7/code/AssetManagementPrototype/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:838:23)
at NativeScriptAngularCompilerPlugin.getCompiledFile (/home/map7/code/AssetManagementPrototype/node_modules/nativescript-dev-webpack/plugins/NativeScriptAngularCompilerPlugin.js:28:26)
at plugin.done.then (/home/map7/code/AssetManagementPrototype/node_modules/@ngtools/webpack/src/loader.js:41:31)
at process._tickCallback (internal/process/next_tick.js:68:7)
@ ./app/home/home.component.ts 11:0-61 216:33-48
@ ./app/home/home.module.ts
@ ../$$_lazy_route_resource lazy namespace object
@ ../node_modules/@angular/core/fesm5/core.js
@ ./app/app.module.ts
@ ./main.ts
更新:试试 nativescript-http-formdata 演示
这也失败了,参考:https://github.com/dotnetdreamer/nativescript-http-formdata/issues/19
【问题讨论】:
-
你现在能解决这个问题吗?
-
@Narendra 我仍然遇到这个问题。刚刚加载了nativescript-http-formdata的6.0分支,又遇到了不同的问题
标签: nativescript okhttp3