Android如何仅针对一种产品风格启用Google Analytics(分析)

时间:2016-05-24 12:39:13

标签: android google-analytics android-flavors

我有一个项目,我有很多种口味(不同的应用程序,不同的appIds与不同的谷歌帐户一起发布)基于相同的基本代码。一切都工作正常,直到我想将谷歌分析添加到我的一个口味,所以我休息了这个教程https://developers.google.com/analytics/devguides/collection/android/v4/#set-up-your-project,并在获得google-services.json文件并将其放入风格specyfic目录后,它正在工作。

但不妥协的是这里的问题:我的其他口味都没有编译,因为没有为他们找到google-services.json。这是gradle失败的日志File google-services.json is missing. The Google Services Plugin cannot function without it.

以下是问题:如何才能为一种风格启用Google Analytics?

任何帮助将不胜感激

编辑1 这是我的gradle文件

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    signingConfigs {
        app1
        app2
        app3
        app4
        app5
        app6
        app7
        app8
        app9
        app10
        app11
        app12
        app13
        app14
        app15
        app16
        app17
        app18
        app19
        app20
        app21
        app22
        app23
        app24
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    useLibrary 'org.apache.http.legacy'
    defaultConfig {
        applicationId "pl.app1"
        minSdkVersion 15
        targetSdkVersion 23
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    buildTypes {
        release {
            minifyEnabled false
            shrinkResources true
            multiDexEnabled = true
            proguardFiles getDefaultProguardFile('proguard-project.pro'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            shrinkResources true
            multiDexEnabled = true
            proguardFiles getDefaultProguardFile('proguard-project.pro'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        app1 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app1
            versionCode = 27
        }
        app2 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app2
            versionCode = 27
        }
        app3 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app3
            versionCode = 27
        }
        app4 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app4
            versionCode = 27
        }
        app5 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app5
            versionCode = 27
        }
        app6 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app6
            versionCode = 27
        }
        app7 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app7
            versionCode = 27
        }
        app8 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app8
            versionCode = 27
        }
        app9 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app9
            versionCode = 27
        }
        app10 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app10
            versionCode = 27
        }
        app11 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app11
            versionCode = 27
        }
        app12 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app12
            versionCode = 27
        }
        app13 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app13
            versionCode = 27
        }
        app14 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app14
            versionCode = 27
        }
        app15 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app15
            versionCode = 27
        }
        app16 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app16
            versionCode = 27
        }
        app17 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app17
            versionCode = 27
        }
        app18 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app18
            versionCode = 26
        }
        app19 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app19
            versionCode = 27
        }
        app20 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app20
            versionCode = 27
        }
        app21 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app21
            versionCode = 27
        }
        app22 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app22
            versionCode = 27
        }
        app23 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app23
            versionCode = 27
        }
        app24 {
            applicationId "xxx"
            versionName "2.7.7"
            signingConfig signingConfigs.app24
            versionCode = 27
        }
    }
}
def Properties props = new Properties()
def propFile = file('../signing.properties')
if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null && props.containsKey('STORE_FILE')) {

        android.signingConfigs.app1.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app1.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app1.keyAlias = props['KEY_ALIAS_APP1']
        android.signingConfigs.app1.keyPassword = props['KEY_PASSWORD_APP1']

        android.signingConfigs.app2.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app2.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app2.keyAlias = props['KEY_ALIAS_APP2']
        android.signingConfigs.app2.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app3.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app3.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app3.keyAlias = props['KEY_ALIAS_APP3']
        android.signingConfigs.app3.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app4.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app4.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app4.keyAlias = props['KEY_ALIAS_APP4']
        android.signingConfigs.app4.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app5.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app5.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app5.keyAlias = props['KEY_ALIAS_APP5']
        android.signingConfigs.app5.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app6.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app6.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app6.keyAlias = props['KEY_ALIAS_APP6']
        android.signingConfigs.app6.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app7.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app7.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app7.keyAlias = props['KEY_ALIAS_APP7']
        android.signingConfigs.app7.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app8.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app8.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app8.keyAlias = props['KEY_ALIAS_APP8']
        android.signingConfigs.app8.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app9.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app9.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app9.keyAlias = props['KEY_ALIAS_APP9']
        android.signingConfigs.app9.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app10.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app10.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app10.keyAlias = props['KEY_ALIAS_APP10']
        android.signingConfigs.app10.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app11.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app11.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app11.keyAlias = props['KEY_ALIAS_11']
        android.signingConfigs.app11.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app12.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app12.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app12.keyAlias = props['KEY_ALIAS_APP12']
        android.signingConfigs.app12.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app13.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app13.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app13.keyAlias = props['KEY_ALIAS_APP13']
        android.signingConfigs.app13.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app14.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app14.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app14.keyAlias = props['KEY_ALIAS_APP14']
        android.signingConfigs.app14.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app15.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app15.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app15.keyAlias = props['KEY_ALIAS_APP15']
        android.signingConfigs.app15.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app16.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app16.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app16.keyAlias = props['KEY_ALIAS_APP16']
        android.signingConfigs.app16.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app17.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app17.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app17.keyAlias = props['KEY_ALIAS__APP17']
        android.signingConfigs.app17.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app18.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app18.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app18.keyAlias = props['KEY_ALIAS_APP18']
        android.signingConfigs.app18.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app19.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app19.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app19.keyAlias = props['KEY_ALIAS__APP19']
        android.signingConfigs.app19.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app20.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app20.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app20.keyAlias = props['KEY_ALIAS_20']
        android.signingConfigs.app20.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app21.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app21.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app21.keyAlias = props['KEY_ALIAS_21']
        android.signingConfigs.app21.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app22.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app22.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app22.keyAlias = props['KEY_ALIAS_22']
        android.signingConfigs.app22.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app23.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app23.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app23.keyAlias = props['KEY_ALIAS_23']
        android.signingConfigs.app23.keyPassword = props['KEY_PASSWORD']

        android.signingConfigs.app24.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.app24.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.app24.keyAlias = props['KEY_ALIAS_24']
        android.signingConfigs.app24.keyPassword = props['KEY_PASSWORD']

    } else {
        android.buildTypes.app1.signingConfig = null
        android.buildTypes.app2.signingConfig = null
        android.buildTypes.app3.signingConfig = null
        android.buildTypes.app4.signingConfig = null
        android.buildTypes.app5.signingConfig = null
        android.buildTypes.app6.signingConfig = null
        android.buildTypes.app7.signingConfig = null
        android.buildTypes.app8.signingConfig = null
        android.buildTypes.app9.signingConfig = null
        android.buildTypes.app10.signingConfig = null
        android.buildTypes.app11.signingConfig = null
        android.buildTypes.app12.signingConfig = null
        android.buildTypes.app13.signingConfig = null
        android.buildTypes.app14.signingConfig = null
        android.buildTypes.app15.signingConfig = null
        android.buildTypes.app16.signingConfig = null
        android.buildTypes.app17.signingConfig = null
        android.buildTypes.app18.signingConfig = null
        android.buildTypes.app19.signingConfig = null
        android.buildTypes.app20.signingConfig = null
        android.buildTypes.app21.signingConfig = null
        android.buildTypes.app22.signingConfig = null
        android.buildTypes.app23.signingConfig = null
        android.buildTypes.app24.signingConfig = null
    }
} else {
    android.buildTypes.app1.signingConfig = null
    android.buildTypes.app2.signingConfig = null
    android.buildTypes.app3.signingConfig = null
    android.buildTypes.app4.signingConfig = null
    android.buildTypes.app5.signingConfig = null
    android.buildTypes.app6.signingConfig = null
    android.buildTypes.app7.signingConfig = null
    android.buildTypes.app8.signingConfig = null
    android.buildTypes.app9.signingConfig = null
    android.buildTypes.app10.signingConfig = null
    android.buildTypes.app11.signingConfig = null
    android.buildTypes.app12.signingConfig = null
    android.buildTypes.app13.signingConfig = null
    android.buildTypes.app14.signingConfig = null
    android.buildTypes.app15.signingConfig = null
    android.buildTypes.app16.signingConfig = null
    android.buildTypes.app17.signingConfig = null
    android.buildTypes.app18.signingConfig = null
    android.buildTypes.app19.signingConfig = null
    android.buildTypes.app20.signingConfig = null
    android.buildTypes.app21.signingConfig = null
    android.buildTypes.app22.signingConfig = null
    android.buildTypes.app23.signingConfig = null
    android.buildTypes.app24.signingConfig = null
}

dependencies {
    compile 'com.viewpagerindicator:library:2.4.1'
    compile 'com.google.android.gms:play-services-gcm:7.5.0'
    compile 'org.apache.commons:commons-compress:1.8.1'
    compile 'commons-io:commons-io:2.4'
    compile 'org.jsoup:jsoup:1.8.2'

    compile 'com.android.support:recyclerview-v7:23.1.1'

    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.1@aar'
    compile 'com.daimajia.androidanimations:library:1.1.3@aar'

    compile 'com.facebook.android:facebook-android-sdk:4.1.0'

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:design:23.1.1'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'org.apmem.tools:layouts:1.10@aar'
    compile 'com.google.android.gms:play-services-analytics:9.0.0'

    compile('com.crashlytics.sdk.android:crashlytics:2.3.2@aar') {
        transitive = true;
    }
}

0 个答案:

没有答案