uni-app HBuilderX版本3.36 使用android离线打包时 微信登录会启动两个应用进程

uni-app HBuilderX版本3.36 使用android离线打包时 微信登录会启动两个应用进程

类别 信息
产品分类 uniapp/App
PC开发环境 Mac
PC版本号 mac os 14.7.1 (23H222)
HBuilderX类型 正式
HBuilderX版本 4.36
手机系统 Android
手机版本号 Android 15
手机厂商 华为
手机机型 p70 pro
页面类型 nvue
vue版本 vue2
打包方式 离线
项目创建方式 HBuilderX

操作步骤:

  1. 开启应用
  2. 使用微信登录
  3. 登录成功
  4. 查看后台,多了一个APP进程

预期结果:

不增加APP进程,只有我本身的APP进程

实际结果:

有两个APP进程

bug描述:

HBuilderX版本3.36 使用android离线打包,使用微信登录会启动两个应用进程

Android manifest中配置

<!-- 应用入口 -->
<activity
android:name="io.dcloud.PandoraEntry"
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale"
android:exported="true"
android:hardwareAccelerated="true"
android:theme="@style/TranslucentTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<data android:scheme="hbuilder" />
<action android:name="android.intent.action.VIEW" />  
<category android:name="android.intent.category.DEFAULT" />  
<category android:name="android.intent.category.BROWSABLE" />  
</intent-filter>  
<intent-filter>  
<data android:mimeType="image/*" />  
<action android:name="android.intent.action.SEND" />  
<category android:name="android.intent.category.DEFAULT" />  
</intent-filter>  
<intent-filter>  
<action android:name="android.intent.action.MAIN" />  
<category android:name="android.intent.category.LAUNCHER" />  
</intent-filter>  
</activity>  
<meta-data  
android:name="dcloud_uninview_background"  
android:value="true" />  

<activity  
android:name="io.dcloud.PandoraEntryActivity"  
android:configChanges="orientation|keyboardHidden|screenSize|mcc|mnc|fontScale|keyboard|smallestScreenSize|screenLayout|screenSize|uiMode"  
android:exported="true"  
android:hardwareAccelerated="true"  
android:launchMode="singleTask"  
android:permission="com.miui.securitycenter.permission.AppPermissionsEditor"  
android:screenOrientation="user"  
android:theme="@style/DCloudTheme"  
android:windowSoftInputMode="adjustResize">  

<intent-filter>  

<category android:name="android.intent.category.DEFAULT" />  

<category android:name="android.intent.category.BROWSABLE" />  

<action android:name="android.intent.action.VIEW" />  

<data android:scheme=" " />  
</intent-filter>  
</activity>  

<meta-data android:value="${wx_secret}" android:name="WX_SECRET"/>  
<meta-data android:value="${wx_appid}" android:name="WX_APPID"/>  
<activity android:name="com.happycheer.tripguide.wxapi.WXEntryActivity"  
android:label="@string/app_name"  
android:exported="true"  
android:launchMode="singleTop">  
<intent-filter>  
<action android:name="android.intent.action.VIEW"/>  
<category android:name="android.intent.category.DEFAULT"/>  
<data android:scheme="${wx_appid}"/>  
</intent-filter>  
</activity>  

<meta-data  android:name="WX_APPID"  android:value="${wx_appid}" />  

<activity  
android:name="io.dcloud.feature.payment.weixin.WXPayProcessMeadiatorActivity"  
android:exported="false"  
android:excludeFromRecents="true"  
android:theme="@style/ProjectDialogTheme" />  
<activity  
android:name="com.happycheer.tripguide.wxapi.WXPayEntryActivity"  
android:exported="true"  
android:theme="@android:style/Theme.Translucent.NoTitleBar"  
android:launchMode="singleTop" />  

更多关于uni-app HBuilderX版本3.36 使用android离线打包时 微信登录会启动两个应用进程的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app HBuilderX版本3.36 使用android离线打包时 微信登录会启动两个应用进程的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在使用uni-app进行Android离线打包时,如果遇到微信登录启动两个应用进程的问题,这通常是由于应用配置或代码实现上的问题导致的。以下是一些可能的解决方案,主要通过代码和配置来展示如何排查和解决问题。

1. 检查AndroidManifest.xml配置

首先,确保AndroidManifest.xml中关于微信SDK的配置是正确的。特别是android:launchMode属性,它决定了Activity的启动模式。如果配置不当,可能会导致应用启动多个进程。

<activity
    android:name=".wxapi.WXEntryActivity"
    android:exported="true"
    android:launchMode="singleTop"
    android:theme="@android:style/Theme.Translucent.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="wxyourappid" />
    </intent-filter>
</activity>

注意android:launchMode="singleTop",这确保了如果WXEntryActivity已经存在于任务栈的顶部,系统不会创建它的新实例。

2. 检查微信SDK初始化代码

确保微信SDK的初始化代码只被调用一次。在App.vue或应用的入口文件中初始化微信SDK。

// #ifdef APP-PLUS
import wx from 'weixin-js-sdk';

plus.runtime.getArgument(function(args) {
    if (args && args.url) {
        // 处理微信回调
        wx.handleIntent(args.url, function(res) {
            // 处理登录结果
        }, function(err) {
            console.error('微信处理失败', err);
        });
    }
});

// 初始化微信SDK(仅调用一次)
wx.config({
    debug: false, // 开启调试模式
    appId: 'yourAppId', // 必填,公众号的唯一标识
    timestamp: , // 必填,生成签名的时间戳
    nonceStr: , // 必填,生成签名的随机串
    signature: ,// 必填,签名
    jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表
});
// #endif

3. 检查应用启动逻辑

确保应用没有因为某些逻辑错误或配置不当而重复启动。检查main.js或应用的启动逻辑,确保没有不必要的多次启动Activity的代码。

4. 使用ProGuard或R8混淆规则

如果使用了ProGuard或R8进行代码混淆,确保微信SDK相关的类没有被错误地混淆或移除。

-keep class com.tencent.mm.opensdk.** { *; }
-dontwarn com.tencent.mm.opensdk.**

通过上述步骤,你应该能够排查并解决uni-app在Android离线打包时微信登录启动两个应用进程的问题。如果问题依旧存在,建议检查微信开发者文档和uni-app社区,看看是否有其他开发者遇到并解决了类似的问题。

回到顶部