【问题标题】:Google App Invite - Failed to startGoogle 应用邀请 - 无法启动
【发布时间】:2016-03-11 16:39:49
【问题描述】:

我正在尝试按照官方documentation 中的所有步骤和GitHub 上的最新配置,在我的项目中使用Google App Invite。

但是,它在调试版和发布版中都不起作用!它仅在两个版本中显示此 Snackbar 消息:

启动失败

它不会在调试模式下留下任何堆栈跟踪,我已经尝试通过使用我的 Google 开发者帐户中的 Alpha 测试安装它来发布版本。这是我在 release 版本上的完整项目配置:

Android Manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.package.name">

    <application
        ... >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
    </application>
    ...
</manifest>

项目级 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta6'
        classpath 'com.google.gms:google-services:2.0.0-beta6'
        // I've tried classpath 'com.google.gms:google-services:2.0.0-alpha5' too

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
...

应用级 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.package.name"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    ...
}
...
dependencies {
    ...
    compile 'com.google.android.gms:play-services-appinvite:8.4.0'
}

apply plugin: 'com.google.gms.google-services'

代码

Intent inviteIntent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
    .setMessage(getString(R.string.invitation_message))
    .setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
    .setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
    .setCallToActionText(getString(R.string.invitation_cta))
    .build();
startActivity(inviteIntent);

我还在我的项目的 app/ 目录中添加了来自 Google Developers Console 的配置文件,其中包括包名称和发布密钥中的 SHA-1。

有什么办法吗?

【问题讨论】:

    标签: android google-app-invites


    【解决方案1】:

    我终于自己找到了答案。实际上,使用 startActivityForResult(intent, requestCode);REQUIRED 而不是仅使用 startActivity(intent); 来使其正常工作。我不明白为什么它是强制性的,因为一些开发人员(比如我自己)不需要回调操作 IMO。

    【讨论】:

    【解决方案2】:

    我不使用classpath 'com.google.gms:google-services:2.0.0-beta6',只使用compile 'com.google.android.gms:play-services-appinvite:8.4.0' 对我有用。

    我的意图:

    Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.appinvite_title))    
           .setMessage(getString(R.string.appinvite_message))                    
           .setDeepLink(Uri.parse(getString(R.string.appinvites_deep_link)))                 
           .build();
    startActivityForResult(intent, REQUEST_INVITE);
    

    这和你的差别不大。你给你的DeepLinkBroadcastReceiver 和你的DeepLinkActivity 编码了吗?

    【讨论】:

    • 如果我不使用classpath 'com.google.gms:google-services:2.0.0-beta6',我会收到以下错误:Gradle sync failed: Plugin with id 'com.google.gms.google-services' not found.DeepLinkBroadcastReceiverDeepLinkActivity 用在接收器上,对吧?我还没有使用这些课程,因为我什至无法发送邀请。
    • 我忘了,你也可以删除应用插件:'com.google.gms.google-services'。是的。
    • 通过验证缓存和重新导入项目来完成;它运行,但仍然无法正常工作(无法启动)!
    • 我在我的 Google Developers Console 上拆分我的项目以生成 google-services.json 用于调试和发布模式。 (因为客户端 ID 只能用于 一个 SHA-1 密钥)我每次为其他版本构建 APK 时都更改了文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 1970-01-01
    相关资源
    最近更新 更多