import { LocationOptions, LocationResponse } from "../interface.uts";
import {
UTSAndroid
} from "io.dcloud.uts";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import ContextCompat from 'androidx.core.content.ContextCompat';
import Manifest from "android.Manifest";
import Looper from "android.os.Looper";
import AMapLocation from "com.amap.api.location.AMapLocation";
import AMapLocationClient from "com.amap.api.location.AMapLocationClient";
import AMapLocationClientOption from "com.amap.api.location.AMapLocationClientOption";
import AMapLocationListener from "com.amap.api.location.AMapLocationListener";
import PackageManager from "android.content.pm.PackageManager";
import Class from 'java.lang.Class';
import Exception from 'java.lang.Exception';
import Activity from 'android.app.Activity';
class PowLocation extends AMapLocationListener {
_locationClient : AMapLocationClient
_options ?: LocationOptions = null
constructor() {
super()
this._locationClient = new AMapLocationClient(UTSAndroid.getAppContext()!)
this._locationClient.setLocationListener(this)
console.log(`222 init client`);
}
override onLocationChanged(location : AMapLocation) {
console.log(`听到了 location ${location}`);
}
startUpdateLocation(options : LocationOptions) {
// 检查权限
console.log(`权限判断开始`);
let permissionStatus = ContextCompat.checkSelfPermission(UTSAndroid.getAppContext()!, Manifest.permission.ACCESS_COARSE_LOCATION)
if (permissionStatus == PackageManager.PERMISSION_DENIED) {
console.log('用户拒绝授权定位')
options.fail(`用户拒绝授权定位`)
return
}
if (permissionStatus != PackageManager.PERMISSION_GRANTED) {
console.log(`当前未授权定位,请求定位权限`);
ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE),
1);//自定义的code
}
console.log(`权限判断结束`);
let amapOption = new AMapLocationClientOption()
amapOption.setNeedAddress(false)
amapOption.setInterval(2000)
this._locationClient.setLocationOption(amapOption)
this._locationClient.startLocation()
}
stopUpdateLocation() {
this._locationClient.stopLocation()
}
/**
* 检查定位的相关配置是否正确
*/
checkLocationConfig() : boolean {
let packageName = UTSAndroid.getAppContext()!.getPackageName();
let appInfo = UTSAndroid.getAppContext()!.getPackageManager()!.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
let metaData = appInfo.metaData
if (metaData == null) {
return false;
}
let adId = metaData.getString("com.amap.api.v2.apikey")
let keyCharNum = adId!.length
if (keyCharNum > 10) {
// 存在超过5个-,说明是符合规则的appkey
console.log(`AndroidManifest.xml中com.amap.api.v2.apikey存在,amapkey设置正确✅`);
return true;
}
console.log(`AndroidManifest.xml中com.amap.api.v2.apikey 不存在,amapkey设置不正确❎`);
// 不符合校验规则,打回
return false;
}
}
const powLocation = new PowLocation()
export function getLocation(options : LocationOptions) {
console.log(`options:${JSON.stringify(options)}`)
}
export function startUpdateLocation(options : LocationOptions) {
powLocation.startUpdateLocation(options)
}
export function stopUpdateLocation() {
powLocation.stopUpdateLocation()
}
export function setAmapKey(key : string) {
console.log(`安卓端设置了${key}`)
powLocation.checkLocationConfig()
}
export function updateAmapPrivacyShow() {
console.log(`natvive updateAmapPrivacyShow`);
AMapLocationClient.updatePrivacyShow(UTSAndroid.getAppContext()!, true, true);
}
export function updateAmapPrivacyAgree() {
console.log(`natvive updateAmapPrivacyAgree`);
AMapLocationClient.updatePrivacyAgree(UTSAndroid.getAppContext()!, true);
}
- 发布:2023-06-30 11:06
- 更新:2023-07-03 15:58
- 阅读:582
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: macos 12.6
HBuilderX类型: Alpha
HBuilderX版本号: 3.8.7
手机系统: Android
手机系统版本号: Android 14
手机厂商: vivo
手机机型: reno
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
制作安卓uts基座
制作安卓uts基座
预期结果:
打包完成
打包完成
实际结果:
打包失败报错
打包失败报错
bug描述:
uts制作自定义安卓基座打包报错,看不出来原因:
[HBuilder] 10:23:18.497 时间: 2023-06-30 10:14:43 类型: Android 公共测试证书 打包失败 错误日志: https://ide.dcloud.net.cn/build/errorLog/e0a0fc00-16eb-11ee-9436-3d9069859bb0
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
[HBuilder] 10:23:18.867 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
[HBuilder] 10:23:18.868 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
[HBuilder] 10:23:18.868 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
[HBuilder] 10:23:18.868 Warning: unexpected element (uri:"", local:"base-extension"). Expected elements are <{}codename>,<{}layoutlib>,<{}api-level>
[HBuilder] 10:23:18.868 e: file://uni_modules/uts-nativepage/utssdk/app-android/src/index.kt:206:41 Type mismatch: inferred type is kotlin.collections.ArrayList<String> / = java.util.ArrayList<String> / but UTSArray<String> was expected
[HBuilder] 10:23:18.869
[HBuilder] 10:23:18.870 FAILURE: Build failed with an exception.
[HBuilder] 10:23:18.870
[HBuilder] 10:23:18.870 What went wrong:
[HBuilder] 10:23:18.870 Execution failed for task ':uni_modules:uts-nativepage:compileReleaseKotlin'.
[HBuilder] 10:23:18.870 > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
[HBuilder] 10:23:18.870 > Compilation error. See log for more details
[HBuilder] 10:23:18.870
[HBuilder] 10:23:18.870 Try:
[HBuilder] 10:23:18.870 > Run with --stacktrace option to get the stack trace.
[HBuilder] 10:23:18.870 > Run with --info or --debug option to get more log output.
[HBuilder] 10:23:18.870 > Run with --scan to get full insights.
[HBuilder] 10:23:18.870
[HBuilder] 10:23:18.870 * Get more help at https://help.gradle.org
[HBuilder] 10:23:18.870
[HBuilder] 10:23:18.870 BUILD FAILED in 29s
[HBuilder] 10:23:18.870
30天只能改一次 (作者)
奇怪,我没有写kt代码,只写了uts代码,这个kt代码是hbulderx翻译之后的代码吧,行数对应不上
2023-06-30 11:22
DCloud_Android_DQQ
回复 j***@qq.com: 你私信一下我QQ ,
2023-06-30 11:30
30天只能改一次 (作者)
回复 DCloud_Android_DQQ: 私了,大哥
2023-06-30 15:48
30天只能改一次 (作者)
回复 DCloud_Android_DQQ: 私了你没加我,,,哥
2023-07-01 19:38