Flutter圈子遇见更好的自己Flutter中文社区

【Android开发学Flutter】微信登录

2019-09-26  本文已影响0人  JairusTse

微信没有提供官方的Flutter插件,所以找了个比较多人用的微信插件:fluwx,项目只需要微信授权登录,还有其他功能大家可以试试。

首先需要在 微信开放平台 注册成为开发者并创建应用,审核通过后得到AppId

引入

pubspec.yaml里添加:

dependencies:
  fluwx: ^1.0.4

添加完成后 flutter pub get

初始化
import 'package:fluwx/fluwx.dart' as fluwx;

fluwx.register(appId:"wxd930ea5d5a258f4f");
fluwx.sendAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test");

fluwx.responseFromAuth.listen((response) {
  //监听授权登录回调
  print("code: " + response.code);
});

获取code后可以传给后台获取access_token

遇到的问题

fluwx 用到 kotlinLuban,编译的时候遇到一些问题:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download kotlin-compiler-embeddable.jar (org.jetbrains.kotlin:kotlin-compiler-embeddable:1.3.40)
      > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.40/kotlin-compiler-embeddable-1.3.40.jar'.
         > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.3.40/kotlin-compiler-embeddable-1.3.40.jar'.
            > Read timed out

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not determine artifacts for top.zibin:Luban:1.1.8
      > Could not get resource 'https://jcenter.bintray.com/top/zibin/Luban/1.1.8/Luban-1.1.8.aar'.
         > Could not HEAD 'https://jcenter.bintray.com/top/zibin/Luban/1.1.8/Luban-1.1.8.aar'.
            > Read timed out

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 3s
Finished with error: Gradle task assembleDebug failed with exit code 1
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 项目目录/build/app/intermediates/transforms/dexBuilder/debug/xx.jar, 
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: top.zibin.luban.BuildConfig

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 58s
Finished with error: Gradle task assembleDebug failed with exit code 1

删除后重新编译就下载成功了 - - !。

android {
    ...
    signingConfigs {//签名配置
        release {//发布版签名配置
            storeFile file("your.jks")//密钥文件路径
            storePassword "psw"//密钥文件密码
            keyAlias "alias"//key别名
            keyPassword "psw"//key密码
        }
        debug {//debug版签名配置
            storeFile file("your.jks")
            storePassword "psw"
            keyAlias "alias"
            keyPassword "psw"
        }
    }
    ...
}

然后就可以直接编译,调起微信登录了。

上一篇下一篇

猜你喜欢

热点阅读