我实施新的谷歌云消息之后从谷歌开发者页面的导游在这里
我已成功运行并测试它.但我现在的问题是我有不同的productFlavors具有不同的applicationId/packageName和不同的GCM项目ID.在google-services.json
具有在被投入/app/google-services.json
不是味道文件夹.
有没有办法让google-services.json
配置与许多口味不同?
我有一个图书馆项目和一个应用程序.我想为图书馆和应用程序提供2种产品口味(商店,开发).当我为应用程序构建商店风味时,我想使用库中的商店风味.此外,当我为应用程序构建dev风格时,我想使用库中的dev风格.我尝试为库和应用程序设置相同的产品风格,但它不起作用.
这是我的配置:
图书馆
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "ro.amarkovits.graddletest.lib"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors{
store{
}
dev{
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Run Code Online (Sandbox Code Playgroud)
我有这些文件:src/main/res/values/strings.xml和src/store/res/values/strings.xml
应用
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId 'ro.amarkovits.mymodule.app'
minSdkVersion 14 …
Run Code Online (Sandbox Code Playgroud) 我Gradle
的就像下面这样:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "io.fabric.tools:gradle:1.+"
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
flavorDimensions "universal"
minSdkVersion 14
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors
{
universal
{
versionCode 1700
versionName "1.7.0"
applicationId "ir.me.project"
resValue …
Run Code Online (Sandbox Code Playgroud) android android-gradle-plugin android-flavors android-studio-3.0
我在我的应用程序中包含gcm的功能,为此,我需要维护两个google-services.json,一个用于调试,一个用于发布版本。怎么做 ??
我可以不使用google-services.json配置gcm吗?
android google-cloud-messaging google-play-services android-gradle-plugin
我收到此错误:
Permission name C2D_MESSAGE is not unique (appears in both my.packagename.permission.C2D_MESSAGE and my.packagename.acc.permission.C2D_MESSAGE) (Previous permission here)
Run Code Online (Sandbox Code Playgroud)
在我的 Android 清单中:
<permission
android:name="my.packagename.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="my.packagename.permission.C2D_MESSAGE" />
Run Code Online (Sandbox Code Playgroud)
问题是在将 applicationIdSuffix 添加到 build.gradle 中的一个风味之后开始的(乍一看似乎与它无关)。
构建.gradle:
flavorDimensions "type"
productFlavors {
acceptance {
dimension="type"
applicationIdSuffix ".acc"
versionNameSuffix "-acc"
}
production {
dimension="type"
applicationIdSuffix ""
versionNameSuffix ""
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.java:
if (BuildConfig.DEBUG) {
GoogleAnalytics.getInstance(context).setDryRun(true);
} else {
setupGoogleAnalytics();
}
Run Code Online (Sandbox Code Playgroud)
我创建了google-services.json的副本。
我已将 google-services.json 添加到:
app\src\acceptance\google-services.json (fake numbers)
app\src\production\google-services.json
Run Code Online (Sandbox Code Playgroud)
我为接受中的键设置了不同的虚假值。我不希望在接受版本中使用 Google Analytics。所以我不想创建单独的 google-services.json。这可能吗?
我将应用程序中的应用模块重命名为演示模块。
classpath "com.google.gms:google-services:3.1.0"
apply plugin: 'com.google.gms.google-services'
当我尝试同步 gradle 时,出现错误:
Error:Execution failed for task ':presentation:processDebugGoogleServices'.
No matching client found for package name 'ru.company.acitive.activelife'
Run Code Online (Sandbox Code Playgroud)
我的 build.gradle 片段:
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.gms:google-services:3.1.0"
}
Run Code Online (Sandbox Code Playgroud)
我的presentation/build.gradle片段:
dependencies {
...
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud) 我正在开发一个 android 应用程序。我有一个 java 文件,我想在调试和发布构建类型中以不同的方式使用它。我知道我可以有不同的资源文件用于调试和发布版本。但是也可以对 Java 文件做同样的事情吗?如何实现这一目标?
我正在尝试将广告添加到我当前的活动中,但该活动未显示任何广告.我还为Android Manifest.xml添加了Internet权限
这是我的
.Gradle文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "sms.and.call.alert.flashlight.lpa.com.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:9.6.0'
compile 'com.google.firebase:firebase-ads:9.6.0'
}
Run Code Online (Sandbox Code Playgroud)
这是MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest …
Run Code Online (Sandbox Code Playgroud)