首先查看官方荣耀路由开发教程 地址:https://developer.huawei.com/consumer/cn/doc/31101
然后下载需要用到的工具:https://developer.huawei.com/consumer/cn/doc/development/smarthome-Library/31105?istab=1
官方文档只写了eclipse+maven的教程,而且还是比较简陋了.本文讲的是从0开始搭建IntelliJ IDEA+gradle+kotlin的开发环境
首先创建一个gradle项目
然后一路下一步就可以了
拷贝相应的文件到指定的目录
接下来把拷贝的jar包添加至工程,并配置相应的设置:
apply plugin: 'osgi'
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
implementation fileTree(dir: 'lib', includes: ['*jar'])
开始编写代码并配置相应的参数:
部分路径根据实际情况填写
jar {
manifest { // the manifest of the default jar is of type OsgiManifest
name = 'test'
instruction 'Bundle-Description', 'test-Description'
instruction 'Built-By', 'yzh'
instruction 'Bundle-Activator', 'com.yzh.test.Activator'
instruction 'Service-Component', 'OSGI-INF/Activator.xml'
instruction 'Build-Jdk', "${sourceCompatibility}"
}
}
task fooJar(type: Jar) {
manifest = osgiManifest {
instruction 'Bundle-Vendor', 'YZH'
}
}
接下来只需要双击jar就可以打出插件包了
取出打出来的test-1.0-SNAPSHOT.jar产物,使用官方的"APK打包工具"就可以打出apk包然后安装了.
以上便是eclipse+maven转IntelliJ IDEA+gradle+kotlin的教程.
接下来讲自动化打apk包并安装
下载附件,并把附件中的这两个文件放至官方的apk打包工具中
在build.gradle中加入以下内容:
ext {
ip = 'http://192.168.3.1'//自己的路由器IP!!!!!!
pwd = '123456' //自己的路由器密码!!!!
pluginFilePath = "D:\YZH\路由器开发\APK打包工具"
jarFile = null
}
jar {
jarFile = archivePath
manifest { // the manifest of the default jar is of type OsgiManifest
name = 'test'
instruction 'Bundle-Description', 'test-Description'
instruction 'Built-By', 'yzh'
instruction 'Bundle-Activator', 'com.yzh.test.Activator'
instruction 'Service-Component', 'OSGI-INF/Activator.xml'
instruction 'Build-Jdk', "${sourceCompatibility}"
}
}
task fooJar(type: Jar) {
manifest = osgiManifest {
instruction 'Bundle-Vendor', 'YZH'
}
}
this.gradle.buildFinished {
jar2apk()
}
def jar2apk() {
println jarFile.getAbsolutePath()
if (jarFile.exists() && jarFile.isFile()) {
def newName = "plugin.jar"
def parentFile = new File(pluginFilePath)
copy {
from jarFile
into parentFile
rename { String fileName ->
newName
}
}
def file = file("$pluginFilePath\\addPlugin.bat")
file.delete()
file.write("cd /d ${pluginFilePath.toLowerCase()}\n" +
"jar2apk.bat $newName cert/openeedebugkeycert.jks openeedebug $ip $pwd")
Runtime.getRuntime().exec("cmd /k start " + file.getAbsolutePath());
}
}
接下来依然是双击jar就可以了