Android

Environment to prepare

L JAVA environment JDK1.8

L Android Studio download address: Android Studio official website OR Android Studio Chinese community

L App offline SDK Download: Download the android SDK version 2.9.8+

Import the uni plug-in native project

L Uniplugin-hello-AS project please find it in App offline SDK

L Click the Android Studio menu option File– >New– >Import ProjectApp offline under the SDK

Plug-in development

Uni-app plug-ins currently support only Module extensions and Component extensions. Adapter extensions are not currently supported. Module extensions (non-UI extensions) are described below.

  1. Create a New Module, File->New->New Module, select Android Library, fill in the information, and click Finish

  1. Edit the build.gradle file of the new Module and add dependencies to make the Module capable of developing uniApp plug-ins
CompileOnly fileTree(dir: 'libs', include: ['*.jar'])\ compileOnly fileTree(dir: '.. /app/libs', include: [' uniapp - v8 - the aar ']) \ compileOnly "com. Android. Support: recyclerview - v7:28.0.0" \ compileOnly "Com. Android. Support: support - v4:28.0.0" \ compileOnly "com. Android. Support: appcompat - v7:28.0.0" \ compileOnly 'com. Alibaba: fastjson: 1.1.46. Android' \ implementation 'com. Facebook. Fresco ": fresco" : 1.13.0'Copy the code

  1. Write logic, create a new Java class in your Module to write your own code logic

  1. Code implementation
    1. We are implementing a Module that needs to inherit from UNI
    2. The extension method must be annotated with @unijsMethod (uiThread = false or True) to determine whether it needs to be run on the UI thread. Default is true. The extension method must be public and easy to call from within UNI

    1. The first argument is passed in as a JSON parameter, which gets the desired argument by key, and the second is a callback function that returns the desired result to the foreground page
    2. If you need other permissions, you need to apply for them in the Androidmanifest.xml file, such as reading and writing calendar

  1. Edit assets/dcloud_uniplugins.json file in the root directory of “app” Module under uniplugin-hello-as project and register it under nativePlugins node. Type: Module, Name specifies the component name to be exposed, class specifies the path to the method, and package name + class name

Dcloud_uniplugins. Json description:

HooksClass: lifecycle proxy (implement AppHookProxy interface class) format (complete package name plus class name) Type: Module or Component type name: Register name Class: Full name of the module or Component entity classCopy the code
  1. Build. Gradle for your app. The name of your component is the name of your new module

This far, and the code development is over, the next is to use the android play offline package verification of studio, portal nativesupport.dcloud.net.cn/AppDocs/use…

Packaging validation

  1. Hbuildx creates a new project and makes the plug-in call through uni.requirenativePlugin

  1. At present, uniApp packaging materials need to be prepared, which will not be described here. AppKey, APPID and Android package name need to be configured in Android Studio, as well as Android certificate alias and secret key

  1. Go to Publish -> Locally packaged -> Generate locally packaged App resources

  1. Copy and paste the generated file into uniplugin-hello-as \app\ SRC \main\assets\apps and change the appID of the dcloud_control. XML file

  1. Android package parameters configuration, package name, certificate alias, etc. (Figure 1), the certificate file needs to be placed in the app (Figure 2) androidmanifest.xml configuration package name and AppKey, is the AppKey of the second step above

  1. Connect the phone, open USB debugging, and click Run

Uniapp packaging

Plug-in generated

Compile aar file to generate Module: Select Gradle > plug-in Module >Tasks > Other >assembleRelease

HBuildX introduces the plug-in

  1. Create nativePlugins -> plugin name -> Android -> plugin AAR file. Store package.json under Android.

Tips: The plug-in ID must be the same as the folder name

  1. Open manifest.json and configure the native plug-in

  1. Cloud packaging for plug-in function verification

IOS

The first step is to get a Mac