我正在努力与谷歌登录Android应用程序。
我按照给定链接Google Sign-In for Android
的步骤,创建了google-services.json
文件,其中包含AndroidMenifest.xml
文件中的相同应用程序ID /包名称。请快速查看以下AndroidMenifest.xml
代码以及google-services.json
文件。
AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="demo.abc.com.deals">
<uses-sdk tools:overrideLibrary="com.facebook" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".ParityApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
/>
<activity
android:name=".views.splash.SplashActivity"
android:configChanges="keyboard|orientation|screenSize"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:configChanges="keyboard|orientation|screenSize"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan" />
</application>
</manifest>
谷歌services.json
"client_info": {
"mobilesdk_app_id": "1:216768689126:android:64277ad0e8ef7db8",
"android_client_info": {
"package_name": "demo.abc.com.deals"
}
的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "demo.abc.com.deals"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dataBinding {
enabled true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
repositories {
mavenCentral()
}
buildTypes {
debug {
debuggable true
applicationIdSuffix '.debug'
buildConfigField("String", "SCHEME", "\"http:\"")
buildConfigField("String", "AUTHORITY", "\"//139.162.46.29\"")
buildConfigField("String", "SERVER_URL", "\"http://139.162.46.29/v3\"")
resValue 'string', 'app_name', 'Parity-SIT'
}
uat.initWith(buildTypes.debug)
uat {
applicationIdSuffix '.uat'
buildConfigField("String", "SCHEME", "\"http:\"")
buildConfigField("String", "AUTHORITY", "\"//139.162.46.29\"")
buildConfigField("String", "SERVER_URL", "\"http://139.162.46.29/v3\"")
resValue 'string', 'app_name', 'Parity-UAT'
}
release {
minifyEnabled false
resValue 'string', 'app_name', 'Parity'
buildConfigField("String", "SCHEME", "\"http:\"")
buildConfigField("String", "AUTHORITY", "\"//139.162.46.29\"")
buildConfigField("String", "SERVER_URL", "\"http://139.162.46.29/v3\"")
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-annotations:25.3.0'
compile 'com.android.support:recyclerview-v7:25.3.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:support-v4:25.3.0'
compile 'com.facebook.android:facebook-android-sdk:4.18.0'
compile 'com.google.android.gms:play-services:9.0.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'me.tatarka.retrolambda'
项目级别build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
classpath 'com.google.gms:google-services:3.0.0'
}
在所有三个文件中,软件包名称为demo.abc.com.deals
,但我仍然收到此错误。
错误:任务':app:processDebugGoogleServices'的执行失败。 找不到包名称'demo.abc.com.deals.debug'的匹配客户端。
我在这里提出了关于同一问题的每一个建议,但对我来说,甚至没有单一的解决方案。 我真的可以使用所有SO用户的建议和经验来处理这个问题。
google-services.json文件添加目录结构
答案 0 :(得分:10)
最后,我在将Google登录到我的应用时修复了此问题,
当我尝试为我的应用设置谷歌登录时,我在应用级别build.gradle
文件中添加了3个构建变体。
当我为每个构建类型添加google-services.json
时,它工作正常,app/src
文件夹中应该有一致的导演。在相应的构建变体文件夹中添加google-services.json
文件后,请检查以下dir结构的屏幕截图。
修改
在所有google-services.json
个文件中,您应根据构建类型指定正确的package_name。
例如,在debug dir中它应该像"package_name": "demo.abc.com.deals.debug"
答案 1 :(得分:0)
在您的gradle底部添加以下代码
apply plugin: 'com.google.gms.google-services'
像这样
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'