Android微信iwxapi.registerApp崩溃

使用最新的微信sdk,版本是6.8.0,调用注册的时候

iwxapi.registerApp("XXX");
dependencies {
    api 'com.tencent.mm.opensdk:wechat-sdk-android:+'
}

一直报下面的错误,并且程序崩溃

java.lang.VerifyError: Verifier rejected class com.tencent.mm.opensdk.channel.a.a: boolean com.tencent.mm.opensdk.channel.a.a.a(android.content.Context, com.tencent.mm.opensdk.channel.a.a$a) failed to verify: boolean com.tencent.mm.opensdk.channel.a.a.a(android.content.Context, com.tencent.mm.opensdk.channel.a.a$a): [0xB4] register v2 has type Precise Reference: java.lang.String but expected Precise Reference: byte[] (declaration of 'com.tencent.mm.opensdk.channel.a.a' appears in /data/app/  -94Wb7XQLDFZJxf5-bws4XQ==/base.apk!classes3.dex)

使用别的方法都没有解决
最后将微信SDK版本降低才不崩溃。最后使用的微信sdk版本如下

com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.3.1

这不是长久之计,因为“微信将于近期发布 targetSdkVersion 30的客户端版本,因Android11系统特性,该微信版本在Android 11及以上系统版本的设备上运行时,授权登录、分享、微信支付等功能受到影响,可能无法正常使用。为了适配Android系统新版本特性,保证微信功能正常使用,请第三方应用2021年11月1日之前进行更新6.8.0”。

如果大家有什么好的解决方法,请赐教。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现微信登录,需要以下步骤: 1. 在微信开放平台上注册账户,创建应用,获取AppID和AppSecret等信息。 2. 在AndroidManifest.xml文件中添加以下内容: ``` <activity android:name=".wxapi.WXEntryActivity" android:exported="true" android:taskAffinity="${applicationId}" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <<data android:scheme="wx{AppID}"/> </intent-filter> </activity> ``` 其中,{AppID}为在微信开放平台上注册应用时获取到的AppID。 3. 创建WXEntryActivity类,并实现IWXAPIEventHandler接口,处理微信登录的响应结果。 ``` public class WXEntryActivity extends AppCompatActivity implements IWXAPIEventHandler { private IWXAPI api; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); api = WXAPIFactory.createWXAPI(this, "{AppID}", true); api.handleIntent(getIntent(), this); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); api.handleIntent(intent, this); } @Override public void onReq(BaseReq req) { } @Override public void onResp(BaseResp resp) { if (resp.getType() == ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX) { switch (resp.errCode) { case BaseResp.ErrCode.ERR_OK: // 登录成功 String code = ((SendAuth.Resp) resp).code; // TODO: 使用code向服务器请求access_token等信息 break; case BaseResp.ErrCode.ERR_USER_CANCEL: // 用户取消登录 break; case BaseResp.ErrCode.ERR_AUTH_DENIED: // 用户拒绝授权 break; default: // 登录失败 break; } } finish(); } } ``` 4. 在登录页面中添加微信登录的按钮,并在点击事件中调用以下代码: ``` SendAuth.Req req = new SendAuth.Req(); req.scope = "snsapi_userinfo"; req.state = "wechat_login"; api.sendReq(req); ``` 其中,apiIWXAPI对象,需要在登录页面中进行初始化。 5. 在服务器端实现微信登录的逻辑,使用code向微信服务器请求access_token等信息,并根据返回的用户信息完成用户的注册或登录等操作。 以上就是AndroidStudio实现微信登录的基本步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值