安卓友盟多渠道打包

第一步

在app BuildGradle添加依赖

 implementation 'com.umeng.sdk:common:latest.integration'
    implementation 'com.umeng.sdk:analytics:latest.integration'
/*配置渠道*/
    flavorDimensions "default"
    productFlavors {
        yingyongbao {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"]
        }
        wandoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
        }
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
        }
    }

把这句话添加到android中

在gradle中添加


buildscript {
    
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }//必须添加,不加可能找不到资源
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        

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

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }//必须添加,不加可能找不到资源
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
maven { url 'https://dl.bintray.com/umsdk/release' }必须添加

 

第二步

配置清单文件


        
        
        
        

    
    
    
    

注 :别忘在清单文件注册App

 

第三步

在app中初始化友盟

 UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE,"");

在Mainactivity中

    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

 

 

 

最后的配置展示

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "tech.wd.com.demo"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    /*配置渠道*/
    flavorDimensions "default"
    productFlavors {
        yingyongbao {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "yingyongbao"]
        }
        wandoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
        }
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "xiaomi"]
        }
    }
 /*   productFlavors {
        //想用哪个渠道就注册那个
        xiaomi {
            manifestPlaceholders = [UMENG_CHANNEL_CALUE:"xiaomi"]
        }
        wandoujia {
            manifestPlaceholders = [UMENG_CHANNEL_CALUE:"wandoujia"]
        }
    }*/
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.umeng.sdk:common:latest.integration'
    implementation 'com.umeng.sdk:analytics:latest.integration'
}

 

 

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

buildscript {
    
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        

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

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/umsdk/release' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

 




    
        
            
                

                
            
        
        
        
        
        
        
    
    
    
    
    
    


package tech.wd.com.demo;

import android.app.Application;

import com.umeng.commonsdk.UMConfigure;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE,"");
    }
}
package tech.wd.com.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void btn1(View view) {
        Toast.makeText(this, "1", Toast.LENGTH_SHORT).show();
    }

    public void btn2(View view) {
        Toast.makeText(this, "2", Toast.LENGTH_SHORT).show();

    }

    public void btn3(View view) {
        Toast.makeText(this, "3", Toast.LENGTH_SHORT).show();

    }

    public void btn4(View view) {
        Toast.makeText(this, "4", Toast.LENGTH_SHORT).show();

    }
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

}

 

你可能感兴趣的:(s)