3

I'm trying to use Google App Invite in my project by following all the steps from its official documentation and latest configuration on GitHub.

However, it's not working at all in both debug and release version! It only shows this Snackbar message in both version:

Failed to start

It does not leave any stack trace in debug mode, and I've tried release version by installing it using Alpha Testing from my Google Developer Account. Here's my complete project configuration on release version:

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>

Project-Level 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
    }
}
...

App-Level 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'

Code

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);

I've also added configuration file from Google Developers Console to app/ directory of my project, which includes the package name and SHA-1 from release key.

Any solution?

simplebe
  • 228
  • 3
  • 14

2 Answers2

5

I finally found the answer myself. Actually, using startActivityForResult(intent, requestCode); is REQUIRED instead of only startActivity(intent); to get it working. I can't understand why it is compulsory since some developers (like myself) don't need the callback action IMO.

simplebe
  • 228
  • 3
  • 14
2

I do not use classpath 'com.google.gms:google-services:2.0.0-beta6' using just compile 'com.google.android.gms:play-services-appinvite:8.4.0' works for me.

My intent:

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);

which doesn't differ much from yours. Have you coded your DeepLinkBroadcastReceiver and your DeepLinkActivity?

GuilhE
  • 11,591
  • 16
  • 75
  • 116
  • 1
    If I don't use `classpath 'com.google.gms:google-services:2.0.0-beta6'`, I get the following error: `Gradle sync failed: Plugin with id 'com.google.gms.google-services' not found.`. `DeepLinkBroadcastReceiver` and `DeepLinkActivity` is used on the receiver, right? I haven't used those class since I can't even send the invitation yet. – simplebe Mar 11 '16 at 17:42
  • I forgot, you can remove apply plugin: 'com.google.gms.google-services' also. Yes they are. – GuilhE Mar 11 '16 at 22:36
  • Done that with validating caches, and re-importing project; It runs, but still not working (Failed to start)! – simplebe Mar 12 '16 at 15:40
  • I split my project on my Google Developers Console to generate `google-services.json` for debug and release mode too. (since Client ID can only be used for _**one**_ SHA-1 key) I changed the file every time I build APK for the other version. – simplebe Mar 12 '16 at 15:58