Skip to content
This repository has been archived by the owner on Dec 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from JoshuaYin/master
Browse files Browse the repository at this point in the history
Request Release 1.0.0
  • Loading branch information
joshua.yin authored Jan 29, 2019
2 parents cacccd3 + 2a6595f commit 89e2032
Show file tree
Hide file tree
Showing 98 changed files with 5,831 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
local.properties
.idea
.DS_Store
build
captures
.externalNativeBuild
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# UCloud NetAnalysis SDK for Android

## 版本
- Current Version:1.0.0

</br></br>
[![](https://img.shields.io/github/release/ucloud/netanalysis-sdk-android.svg)](https://github.com/ucloud/netanalysis-sdk-android)
[![](https://img.shields.io/github/last-commit/ucloud/netanalysis-sdk-android.svg)](https://github.com/ucloud/netanalysis-sdk-android)
[![](https://img.shields.io/github/commits-since/ucloud/netanalysis-sdk-android/latest.svg)](https://github.com/ucloud/netanalysis-sdk-android)

## 运行环境
### Android
Expand Down Expand Up @@ -34,8 +33,6 @@ NetAnalysis SDK依赖于Gson、Retrofit2.0
以下是NetAnalysis SDK所需要的Android权限,请确保您的AndroidManifest.xml文件中已经配置了这些权限,否则,SDK将无法正常工作。
``` xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
```
Expand Down
8 changes: 8 additions & 0 deletions UNetAnalysisLib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
local.properties
.idea
.DS_Store
build
captures
.externalNativeBuild
162 changes: 162 additions & 0 deletions UNetAnalysisLib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
import proguard.gradle.ProGuardTask

apply plugin: 'com.android.library'

android {
compileSdkVersion 26

defaultConfig {
minSdkVersion 10
targetSdkVersion 26
versionCode 0
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
jniDebuggable true
buildConfigField('String', 'UCLOUD_API_IPIP', toJavaCodeString(UCLOUD_API_IPIP))
buildConfigField('String', 'UCLOUD_API_IP_LIST', toJavaCodeString(UCLOUD_API_IP_LIST))
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
jniDebuggable false
buildConfigField('String', 'UCLOUD_API_IPIP', toJavaCodeString(UCLOUD_API_IPIP))
buildConfigField('String', 'UCLOUD_API_IP_LIST', toJavaCodeString(UCLOUD_API_IP_LIST))
}
}
lintOptions {
abortOnError false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
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.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
}


class Utils {
static def r = new Random(System.currentTimeMillis())
}

String toJavaCodeString(String string) {
byte[] b = string.getBytes();
int c = b.length;
StringBuffer sb = new StringBuffer();

sb.append("new Object(){");
sb.append("int t;");
sb.append("public String toString() {");
sb.append("byte[] buf = new byte[");
sb.append(c);
sb.append("];");

for (int i = 0; i < c; ++i) {
int t = Utils.r.nextInt();
int f = Utils.r.nextInt(24) + 1;

t = (t & ~(0xff << f)) | (b[i] << f);

sb.append("t = ");
sb.append(t);
sb.append(";");
sb.append("buf[");
sb.append(i);
sb.append("] = (byte) (t >>> ");
sb.append(f);
sb.append(");");
}

sb.append("return new String(buf);");
sb.append("}}.toString()");

return sb.toString();
}

//task makeJar(type: Copy) {
// delete 'build/outputs/BSBandLib.jar'
// from('build/intermediates/bundles/release/')
// into('build/outputs/')
// include('classes.jar')
// rename('classes.jar', 'BSBandLib.jar')
//}
//
//makeJar.dependsOn(build)

task clearJar(type: Delete) {
delete 'build/libs/UNetAnalysisLib.jar'
delete 'build/libs/proguard-UNetAnalysisLib.jar'
}

task makeJar(dependsOn: ['clearJar', 'build', 'compileReleaseJavaWithJavac'], type: Jar) {
//指定生成的jar名
// appendix = "demo"
baseName = "UNetAnalysisLib"
// version = "1.0.0"
// classifier = "release"
//后缀名
extension = "jar"
//最终的 Jar 包名,如果没设置,默认为 [baseName]-[appendix]-[version]-[classifier].[extension]
// archiveName = "CCBWristBand_jd.jar"
//需打包的资源所在的路径集
// from(project.zipTree("libs/依赖的第三方库"))
//初始化资源路径集
from project.buildDir.absolutePath + "/intermediates/classes/release/"
//打包到jar后的目录结构
// into('cn/com/jd/')
//去除路径集下部分的资源
// exclude "**/BuildConfig.class"
exclude "**/R.class"
exclude "android/**"
exclude { it.name.startsWith('R$'); }
//只导入资源路径集下的部分资源
// include "org/chaos/demo/jar/**/*.class"
//注: exclude include 支持可变长参数
}

task makeProguardJar(dependsOn: ['makeJar'], type: ProGuardTask) {
//Android 默认的 proguard 文件
configuration android.getDefaultProguardFile('proguard-android.txt')
//manifest 注册的组件对应的 proguard 文件
configuration project.buildDir.absolutePath + "/intermediates/proguard-rules/release/aapt_rules.txt"
configuration 'proguard-rules.pro'
String inJar = makeJar.archivePath.getAbsolutePath()
//输入 jar
injars inJar
//输出 jar
outjars inJar.substring(0, inJar.lastIndexOf(File.separator)) + "/proguard-${makeJar.archiveName}"
//设置不删除未引用的资源(类,方法等)
dontshrink
Plugin plugin = getPlugins().hasPlugin(AppPlugin) ?
getPlugins().findPlugin(AppPlugin) :
getPlugins().findPlugin(LibraryPlugin)
if (plugin != null) {
List<String> runtimeJarList
if (plugin.getMetaClass().getMetaMethod("getRuntimeJarList")) {
runtimeJarList = plugin.getRuntimeJarList()
} else if (android.getMetaClass().getMetaMethod("getBootClasspath")) {
runtimeJarList = android.getBootClasspath()
} else {
runtimeJarList = plugin.getBootClasspath()
}
for (String runtimeJar : runtimeJarList) {
//给 proguard 添加 runtime
libraryjars(runtimeJar)
}
}
}

103 changes: 103 additions & 0 deletions UNetAnalysisLib/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-target 1.8
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-optimizationpasses 5
-dontusemixedcaseclassnames
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-keepparameternames
-verbose
-ignorewarnings

-keep public class * extends android.app.Activity

-keep public class * extends android.app.Application

-keep public class * extends android.app.Service

-keep public class * extends no.nordicsemi.android.dfu.DfuBaseService

-keep public class * extends android.content.BroadcastReceiver

-keep public class * extends android.content.ContentProvider

-keep public class * extends android.app.backup.BackupAgentHelper

-keep public class * extends android.preference.Preference

-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembers class * {
public <init>(android.content.Context,android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context,android.util.AttributeSet,int);
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keep class * extends android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

# Keep - Library. Keep all public and protected classes, fields, and methods.
#-keep public class * {
# public <fields>;
# public <methods>;
#}

# -------------------------------------------------------------
# com.ucloud.library.netanalysislib.UCNetAnalysisManager
#-keep class com.ucloud.library.netanalysis.UCNetAnalysisManager {
# public <fields>;
# public <methods>;
#}

# com.ucloud.library.netanalysislib.**
-keep class com.ucloud.library.netanalysis.** {
public <fields>;
public <methods>;
}

# -------------------------------------------------------------
# Retrofit2
-keep class * extends retrofit2.Callback {
*;
}

# -------------------------------------------------------------
# Gson
-keep class com.google.gson.** {
*;
}

# -------------------------------------------------------------
# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ucloud.library.netanalysis;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.ucloud.library.netanalysis.test", appContext.getPackageName());
}
}
7 changes: 7 additions & 0 deletions UNetAnalysisLib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ucloud.library.netanalysis">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

</manifest>
Loading

0 comments on commit 89e2032

Please sign in to comment.