Skip to content

Commit 1dc8f59

Browse files
committed
Library Ported to HarmonyOS
Library Ported to HarmonyOS. Sample app still In-Progress.
1 parent c291e3d commit 1dc8f59

File tree

41 files changed

+578
-553
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+578
-553
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
env:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2323
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
24-
uses: applibgroup/HarmonyOsSdk@v1.2
24+
uses: applibgroup/HarmonyOsSdk@v1.3
2525
- name: Upload Artifact
2626
uses: actions/upload-artifact@v2
2727
with:

.gitignore

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
*.iml
22
.gradle
33
/local.properties
4-
/.idea/caches
5-
/.idea/libraries
6-
/.idea/modules.xml
7-
/.idea/workspace.xml
8-
/.idea/navEditor.xml
9-
/.idea/assetWizardSettings.xml
4+
/.idea/
105
.DS_Store
116
/build
127
/captures

build.gradle

+25-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
apply plugin: 'com.huawei.ohos.app'
23

4+
//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510
5+
ohos {
6+
compileSdkVersion 6
7+
defaultConfig {
8+
compatibleSdkVersion 5
9+
}
10+
}
11+
312
buildscript {
413
repositories {
5-
google()
14+
maven {
15+
url 'https://repo.huaweicloud.com/repository/maven/'
16+
}
17+
maven {
18+
url 'https://developer.huawei.com/repo/'
19+
}
20+
jcenter()
621
}
722
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.2.2'
9-
10-
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
11-
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
12-
13-
// NOTE: Do not place your application dependencies here; they belong
14-
// in the individual module build.gradle files
23+
classpath 'com.huawei.ohos:hap:2.4.4.2'
24+
classpath 'com.huawei.ohos:decctest:1.2.4.0'
1525
}
1626
}
1727

1828
allprojects {
1929
repositories {
30+
maven {
31+
url 'https://repo.huaweicloud.com/repository/maven/'
32+
}
33+
maven {
34+
url 'https://developer.huawei.com/repo/'
35+
}
36+
jcenter()
2037
}
2138
}
22-
23-
task clean(type: Delete) {
24-
delete rootProject.buildDir
25-
}

cacheutilslibrary/.gitignore

-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea/caches
5-
/.idea/libraries
6-
/.idea/modules.xml
7-
/.idea/workspace.xml
8-
/.idea/navEditor.xml
9-
/.idea/assetWizardSettings.xml
10-
.DS_Store
111
/build
12-
/captures
13-
.externalNativeBuild
14-
/entry/.preview
15-
.cxx

cacheutilslibrary/build.gradle

+16-108
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,27 @@
1-
apply plugin: 'com.android.library'
2-
3-
// This is the library version used when deploying the artifact
4-
version = "1.1.0"
5-
6-
android {
7-
compileSdkVersion 23
8-
buildToolsVersion "22.0.1"
9-
1+
apply plugin: 'com.huawei.ohos.library'
2+
//For instructions on signature configuration, see https://developer.harmonyos.com/en/docs/documentation/doc-guides/ide_debug_device-0000001053822404#EN-US_TOPIC_0000001154985555__section1112183053510
3+
ohos {
4+
compileSdkVersion 6
105
defaultConfig {
11-
minSdkVersion 15
12-
targetSdkVersion 30
13-
versionCode 1
14-
versionName "1.1.0"
6+
compatibleSdkVersion 5
157
}
168
buildTypes {
179
release {
18-
minifyEnabled false
19-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
10+
proguardOpt {
11+
proguardEnabled false
12+
rulesFiles 'proguard-rules.pro'
13+
}
2014
}
2115
}
16+
2217
}
2318

2419
dependencies {
25-
implementation 'com.google.code.gson:gson:2.2.2'
26-
implementation 'commons-io:commons-io:2.4'
27-
}
28-
29-
def siteUrl = 'https://github.com/westlinkin/CacheUtilsLibrary' // Homepage URL of the library
30-
def gitUrl = 'https://github.com/westlinkin/CacheUtilsLibrary.git' // Git repository URL
31-
group = "com.lifeofcoding" // Maven Group ID for the artifact
32-
//
33-
//install {
34-
// repositories.mavenInstaller {
35-
// // This generates POM.xml with proper parameters
36-
// pom {
37-
// project {
38-
// packaging 'aar'
39-
//
40-
// // Add your description here
41-
// name 'CacheUtilsLibrary'
42-
// description = 'This is a simple Android util library to write any type of data into cache files and then read them later, using Gson to serialize and deserialize these data.'
43-
// url siteUrl
44-
//
45-
// // Set your license
46-
// licenses {
47-
// license {
48-
// name 'The Apache Software License, Version 2.0'
49-
// url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
50-
// }
51-
// }
52-
// developers {
53-
// developer {
54-
// id 'westlinkin'
55-
// name 'Wesley Lin'
56-
57-
// }
58-
// }
59-
// scm {
60-
// connection gitUrl
61-
// developerConnection gitUrl
62-
// url siteUrl
63-
//
64-
// }
65-
// }
66-
// }
67-
// }
68-
//}
20+
implementation fileTree(dir: 'libs', include: ['*.jar'])
21+
testImplementation 'junit:junit:4.13'
22+
// https://mvnrepository.com/artifact/com.google.code.gson/gson
23+
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
24+
// https://mvnrepository.com/artifact/commons-io/commons-io
25+
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
6926

70-
task sourcesJar(type: Jar) {
71-
from android.sourceSets.main.java.srcDirs
72-
classifier = 'sources'
7327
}
74-
75-
task javadoc(type: Javadoc) {
76-
source = android.sourceSets.main.java.srcDirs
77-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
78-
}
79-
80-
task javadocJar(type: Jar, dependsOn: javadoc) {
81-
classifier = 'javadoc'
82-
from javadoc.destinationDir
83-
}
84-
artifacts {
85-
archives javadocJar
86-
archives sourcesJar
87-
}
88-
89-
Properties properties = new Properties()
90-
properties.load(project.rootProject.file('local.properties').newDataInputStream())
91-
//
92-
//// https://github.com/bintray/gradle-bintray-plugin
93-
//bintray {
94-
// user = properties.getProperty("bintray.user")
95-
// key = properties.getProperty("bintray.apikey")
96-
//
97-
// configurations = ['archives']
98-
// pkg {
99-
// repo = "maven"
100-
// // it is the name that appears in bintray when logged
101-
// name = "CacheUtilsLibrary"
102-
// websiteUrl = siteUrl
103-
// vcsUrl = gitUrl
104-
// licenses = ["Apache-2.0"]
105-
// publish = true
106-
// version {
107-
// gpg {
108-
// sign = true //Determines whether to GPG sign the files. The default is false
109-
// passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
110-
// }
111-
//// mavenCentralSync {
112-
//// sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
113-
//// user = properties.getProperty("bintray.oss.user") //OSS user token
114-
//// password = properties.getProperty("bintray.oss.password") //OSS user password
115-
//// close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
116-
//// }
117-
// }
118-
// }
119-
//}

cacheutilslibrary/consumer-rules.pro

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Add har specific ProGuard rules for consumer here.

cacheutilslibrary/proguard-rules.pro

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
# Add project specific ProGuard rules here.
2-
# By default, the flags in this file are appended to flags specified
3-
# in /Users/Linkin/Study/Android/android-sdk-macosx/tools/proguard/proguard-android.txt
4-
# You can edit the include path and order by changing the proguardFiles
5-
# directive in build.gradle.
6-
#
7-
# For more details, see
8-
# http://developer.android.com/guide/developing/tools/proguard.html
9-
10-
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}
1+
# config module specific ProGuard rules here.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"app": {
3+
"bundleName": "org.applibgroup.codelabs.myapplication",
4+
"vendor": "lifeofcoding",
5+
"version": {
6+
"code": 1000000,
7+
"name": "1.0.0"
8+
}
9+
},
10+
"deviceConfig": {
11+
"default": {
12+
"network": {
13+
"cleartextTraffic": true,
14+
"usesClearText": true
15+
}
16+
}
17+
},
18+
"module": {
19+
"package": "com.lifeofcoding.cacheutlislibrary",
20+
"deviceType": [
21+
"phone",
22+
"tablet",
23+
"tv"
24+
],
25+
"distro": {
26+
"deliveryWithInstall": true,
27+
"moduleType": "har",
28+
"moduleName": "cacheutilslibrary"
29+
}
30+
}
31+
}

cacheutilslibrary/src/main/java/com/lifeofcoding/cacheutlislibrary/CacheUtils.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.lifeofcoding.cacheutlislibrary;
22

3-
import android.content.Context;
4-
import android.text.TextUtils;
5-
import android.util.Log;
6-
73
import com.google.gson.reflect.TypeToken;
84

5+
import ohos.agp.render.render3d.BuildConfig;
6+
import ohos.app.Context;
97
import org.apache.commons.io.FileUtils;
108
import org.apache.commons.io.IOUtils;
119

@@ -30,12 +28,13 @@ public class CacheUtils {
3028

3129
private static final String TAG = "CACHE_UTILS";
3230

31+
private CacheUtils() {}
3332
public static void configureCache(Context context) {
34-
BASE_CACHE_PATH = context.getApplicationInfo().dataDir + File.separator + "files" + File.separator + "CacheUtils";
33+
BASE_CACHE_PATH = context.getApplicationInfo().getEntryDir() + File.separator + "files" + File.separator + "CacheUtils";
3534

3635
if (new File(BASE_CACHE_PATH).mkdirs()) {
3736
if (BuildConfig.DEBUG)
38-
Log.d(TAG, BASE_CACHE_PATH + " created.");
37+
LogUtil.debug(TAG, BASE_CACHE_PATH + " created.");
3938
}
4039
}
4140

@@ -52,8 +51,8 @@ private static <T> List<Map<String, T>> dataMapsFromJson(String dataString) {
5251
return GsonHelper.buildGson().fromJson(dataString, listType);
5352
} catch (Exception e) {
5453
if (BuildConfig.DEBUG)
55-
Log.d(TAG, "failed to read json" + e.toString());
56-
return new ArrayList<Map<String, T>>();
54+
LogUtil.debug(TAG, "failed to read json" + e.toString());
55+
return new ArrayList<>();
5756
}
5857
}
5958

@@ -62,7 +61,7 @@ private static <T> String dataMapstoJson(List<Map<String, T>> dataMaps) {
6261
return GsonHelper.buildGson().toJson(dataMaps);
6362
} catch (Exception e) {
6463
if (BuildConfig.DEBUG)
65-
Log.d(TAG, "failed to write json" + e.toString());
64+
LogUtil.debug(TAG, "failed to write json" + e.toString());
6665
return "[]";
6766
}
6867
}
@@ -76,7 +75,7 @@ public static String readFile(String fileName) {
7675
return IOUtils.toString(new FileInputStream(pathForCacheEntry(fileName)), ENCODING);
7776
} catch (IOException e) {
7877
if (BuildConfig.DEBUG)
79-
Log.d(TAG, "read cache file failure" + e.toString());
78+
LogUtil.debug(TAG, "read cache file failure" + e.toString());
8079
return null;
8180
}
8281
}
@@ -90,7 +89,7 @@ public static void writeFile(String fileName, String fileContent) {
9089
IOUtils.write(fileContent, new FileOutputStream(pathForCacheEntry(fileName)), ENCODING);
9190
} catch (IOException e) {
9291
if (BuildConfig.DEBUG)
93-
Log.d(TAG, "write cache file failure" + e.toString());
92+
LogUtil.debug(TAG, "write cache file failure" + e.toString());
9493
}
9594
}
9695

@@ -115,7 +114,7 @@ private static <T> T objectFromJson(String dataString, Type t) {
115114
return GsonHelper.buildGson().fromJson(dataString, t);
116115
} catch (Exception e) {
117116
if (BuildConfig.DEBUG)
118-
Log.v(TAG, "failed to read json" + e.toString());
117+
LogUtil.info(TAG, "failed to read json" + e.toString());
119118
return null;
120119
}
121120
}
@@ -125,7 +124,7 @@ private static <T> String objectToJson(T o) {
125124
return GsonHelper.buildGson().toJson(o);
126125
} catch (Exception e) {
127126
if (BuildConfig.DEBUG)
128-
Log.v(TAG, "failed to write json" + e.toString());
127+
LogUtil.info(TAG, "failed to write json" + e.toString());
129128
return null;
130129
}
131130
}
@@ -157,7 +156,7 @@ private static <T> Map<String, T> dataMapFromJson(String dataString) {
157156
return GsonHelper.buildGson().fromJson(dataString, t);
158157
} catch (Exception e) {
159158
if (BuildConfig.DEBUG)
160-
Log.v(TAG, "failed to read json" + e.toString());
159+
LogUtil.info(TAG, "failed to read json" + e.toString());
161160
return new HashMap<String,T>();
162161
}
163162
}
@@ -167,7 +166,7 @@ private static <T> String dataMaptoJson(Map<String, T> dataMap) {
167166
return GsonHelper.buildGson().toJson(dataMap);
168167
} catch (Exception e) {
169168
if (BuildConfig.DEBUG)
170-
Log.v(TAG, "failed to write json" + e.toString());
169+
LogUtil.info(TAG, "failed to write json" + e.toString());
171170
return "{}";
172171
}
173172
}

0 commit comments

Comments
 (0)