nopilot
nopilot
  • 发布:2024-07-24 15:26
  • 更新:2024-07-31 17:45
  • 阅读:218

【报Bug】plus.android.importClass("com.google.android.play.core。。。) is not defined

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: ventura13.01

HBuilderX类型: 正式

HBuilderX版本号: 4.23

手机系统: Android

手机系统版本号: Android 13

手机厂商: 三星

手机机型: S22

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

代码:var ReviewManagerFactory = plus.android.importClass("com.google.android.play.core.review.ReviewManagerFactory");

错误:Error initializing review flow: ReviewManagerFactory is not defined

代码:var Task = plus.android.importClass("com.google.android.play.core.tasks.Task");

成功

操作步骤:

自定义基座。targetSdkVersion=34。manifest针对native.js无特殊配置。

代码:var ReviewManagerFactory = plus.android.importClass("com.google.android.play.core.review.ReviewManagerFactory");

错误:Error initializing review flow: ReviewManagerFactory is not defined

代码:var Task = plus.android.importClass("com.google.android.play.core.tasks.Task");

成功

预期结果:

成功导入class

实际结果:

报错class不存在

bug描述:

同样测试程序内逐行打印,

报错代码:var ReviewManagerFactory = plus.android.importClass("com.google.android.play.core.review.ReviewManagerFactory");

错误:Error initializing review flow: ReviewManagerFactory is not defined

成功代码:var Task = plus.android.importClass("com.google.android.play.core.tasks.Task");

成功

2024-07-24 15:26 负责人:无 分享
已邀请:
DCloud_App_Array

DCloud_App_Array

标准基座不包含上述示例中的“com.google.android.play.core.review.ReviewManagerFactory”class,需要自定义基座并确保把这些依赖的库包含在安装包中。建议使用uni原生插件或uts插件来扩展。

  • nopilot (作者)

    可以不开发uni原生插件实现,在自定义基座和云打包时引用这个依赖吗?还是说必须自己开发uni原生插件?

    2024-07-31 15:30

  • DCloud_App_Array

    回复 nopilot: 只有uni原生插件或uts插件才可以配置使用依赖(或三方SDK库)。

    2024-07-31 15:58

  • nopilot (作者)

    回复 DCloud_App_Array: 尝试弄了个安卓原生本地插件,但云打包报错,能帮着看看是什么问题吗?谢谢! https://app.liuyingyong.cn/build/errorLog/f9452f10-4ed4-11ef-bd53-d5589cc62c33

    2024-07-31 16:36

nopilot

nopilot (作者)

插件module的build.gradle如下:

apply plugin: 'com.android.library'

android {
compileSdkVersion 34
namespace 'com.xxx.uniplugin_inappreview'
defaultConfig {
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"

    testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'  
}  

buildTypes {  
    release {  
        minifyEnabled false  
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
    }  
}  
compileOptions {  
    sourceCompatibility JavaVersion.VERSION_1_8  
    targetCompatibility JavaVersion.VERSION_1_8  
}  

}

//导入aar需要的配置
repositories {
// google()
// mavenCentral()
flatDir {
dirs 'libs'
}
}

dependencies {
// implementation 'com.google.android.play:core:1.8.0'
implementation 'com.google.android.play:review:2.0.1'
//必须添加的依赖
// implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
// compileOnly 'androidx.core:core:1.13.0'
// compileOnly 'androidx.fragment:fragment:1.8.2.0'
// compileOnly 'androidx.recyclerview:recyclerview:1.3.2.0'
// compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'
// compileOnly 'com.alibaba:fastjson:1.2.83'
// compileOnly 'androidx.appcompat:appcompat:1.7.0'

compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'  
implementation 'com.facebook.fresco:fresco:1.13.0'  

//必须添加的依赖  
compileOnly 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'  
compileOnly 'androidx.core:core:1.1.0'  
compileOnly 'androidx.fragment:fragment:1.1.0'  
compileOnly 'androidx.appcompat:appcompat:1.1.0'  
compileOnly 'androidx.recyclerview:recyclerview:1.1.0'  
compileOnly 'com.alibaba:fastjson:1.2.83'  

compileOnly fileTree(dir: 'libs', include: ['*.jar'])  
compileOnly fileTree(include: ['uniapp-v8-release.aar'], dir: '../app/libs')  

implementation 'com.google.android.material:material:1.12.0'  
testImplementation 'junit:junit:4.13.2'  
androidTestImplementation 'androidx.test.ext:junit:1.2.1.5'  
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'  

}

  • DCloud_App_Array

    从错误日志看是找不到res中的资源,关键错误信息如下:


    > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction  
    > Android resource linking failed
    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: style attribute 'attr/colorPrimaryVariant (aka com.tripsters.japanmetro:attr/colorPrimaryVariant)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: style attribute 'attr/colorOnPrimary (aka com.tripsters.japanmetro:attr/colorOnPrimary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: style attribute 'attr/colorSecondary (aka com.tripsters.japanmetro:attr/colorSecondary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: style attribute 'attr/colorSecondaryVariant (aka com.tripsters.japanmetro:attr/colorSecondaryVariant)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: style attribute 'attr/colorOnSecondary (aka com.tripsters.japanmetro:attr/colorOnSecondary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values/values.xml:11:5-23:13: AAPT: error: resource attr/colorPrimaryVariant (aka com.tripsters.japanmetro:attr/colorPrimaryVariant) not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: style attribute 'attr/colorPrimaryVariant (aka com.tripsters.japanmetro:attr/colorPrimaryVariant)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: style attribute 'attr/colorOnPrimary (aka com.tripsters.japanmetro:attr/colorOnPrimary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: style attribute 'attr/colorSecondary (aka com.tripsters.japanmetro:attr/colorSecondary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: style attribute 'attr/colorSecondaryVariant (aka com.tripsters.japanmetro:attr/colorSecondaryVariant)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: style attribute 'attr/colorOnSecondary (aka com.tripsters.japanmetro:attr/colorOnSecondary)' not found.

    ERROR:/home/[Name]/.gradle/caches/transforms-3/f7aa6e000345bdf4beec70d9b774c113/transformed/jetified-uniplugin_inappreview-release/res/values-night-v8/values-night-v8.xml:3:5-15:13: AAPT: error: resource attr/colorPrimaryVariant (aka com.tripsters.japanmetro:attr/colorPrimaryVariant) not found.

    注意:查看这里看下云端打包环境:https://uniapp.dcloud.net.cn/tutorial/app-env.html

    2024-07-31 16:49

  • nopilot (作者)

    回复 DCloud_App_Array: 是的。在android studio各种build clean/rebuild;gradle clean;grade aR都运行了。现在不确定到底是插件侧build的问题,还是云打包侧的问题。您的判断呢?

    2024-07-31 17:42

  • nopilot (作者)

    回复 DCloud_App_Array: 看hbuilder更新后,现在只能升级到4.24,还无法升级到4.25啊

    2024-07-31 17:48

nopilot

nopilot (作者)

我用的hbuilderX 4.23,晚些升级到4.25试试,因为google play要求targetSdkVersion至少是34了

要回复问题请先登录注册