小心立早鱼
小心立早鱼
  • 发布:2023-06-01 14:29
  • 更新:2023-06-05 12:49
  • 阅读:533

关于uts离线打包的场景

分类:uni-app

uniapp中使用离线SDK打出来的基座包似乎调用不了UTS的插件

// #ifdef APP-PLUS  
  import * as androidModule from '../../uni_modules/buguniao-androidId'  
  // #endif  
....  
onLoad() {  
    console.log('androidId ==> ', androidModule.getAndroidId())  
}

报错信息:
14:15:04.205 [Vue warn]: Error in onLoad hook: "SyntaxError: Unexpected end of JSON input"

(found at pages/index/index.vue:1)
14:15:04.210 SyntaxError: Unexpected end of JSON inpu

uts的代码:

import Settings from  "android.provider.Settings";  
import { UTSAndroid } from "io.dcloud.uts";  

export function getAndroidId():string {  
  let deviceId:string;  
  const context = UTSAndroid.getAppContext();  
  deviceId = Settings.Secure.getString(context?.getContentResolver(), Settings.Secure.ANDROID_ID);  
  return deviceId;  
}

hbuildX版本和离线SDK使用3.8.4(昨天是3.8.3也试过,不行的)
但是当我使用官方标准基座这个代码又能使用起来
离线包已引入utsplugin-release.aar

2023-06-01 14:29 负责人:无 分享
已邀请:
DCloud_Android_DQQ

DCloud_Android_DQQ

需要额外注意3点:

1 gradle 版本提升到 7.3.3以及以上

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip

2 顶级build.gradle 需要配置class path

buildscript {  
 dependencies {  
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"  
 }  
}
DCloud_App_Array

DCloud_App_Array

还需要添加以下依赖:

      "com.squareup.okhttp3:okhttp:3.12.12"  
      "com.alibaba:fastjson:1.2.83"  
      "androidx.core:core-ktx:1.6.0"  
      "org.jetbrains.kotlin:kotlin-stdlib:1.8.10"  
      "org.jetbrains.kotlin:kotlin-reflect:1.6.0"  
      "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8"  
      "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8"

要回复问题请先登录注册