-
Notifications
You must be signed in to change notification settings - Fork 207
sdk access
xu.jingyu edited this page Feb 14, 2020
·
11 revisions
Open build.gradle and add the following code.
android {
defaultConfig {
ndk {
abiFilters "armeabi-v7a"
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0+'
implementation "androidx.recyclerview:recyclerview:1.1.0+"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
// core library
implementation "com.immomo.mlncore:core:1.0.0"
// view、tool bridge library
implementation "com.immomo.mls:mln:1.0.0"
// code generation library
annotationProcessor "com.immomo.mls:processor:1.0.0"
// hotreload
debugImplementation "com.immomo.luanative:hotreload:1.0.0"
releaseImplementation "com.immomo.luanative:hotreload_empty:1.0.0"
// use with hot reload
debugImplementation "com.google.protobuf:protobuf-lite:3.0.1"
}
Create a new global class to inherit Application and initialize Lua Engine in onCreate
as follows:
MLSEngine.init(application, BuildConfig.DEBUG)
.setLVConfig(new LVConfigBuilder(application)
.setRootDir(rootDir) //set lua root directory
.setImageDir(imageDir) //set lua picture root directory
.setCacheDir(cacheDir) //set lua cache directory
.setGlobalResourceDir(gResDir) //set the resource file directory
.build())
.setImageProvider(new GlideImageProvider())//lua loading image tool, if it is not implemented, the image cannot be displayed
.build(true);
Note:
- The directory addresses in LVConfig need to be configured correctly.
- ImageProvider needs to define its own image loading class.(see the implementation in MLN-Android)
- Remember to register the Application in AndroidManifest.xml.
// can edit in Activity, Fragment or any view
FrameLayout frameLayout = new FrameLayout(this);
setContentView(frameLayout);
instance = new MLSInstance(this, true, true);
instance.setContainer(frameLayout);
InitData initData = new InitData("file://android_asset/demo.lua"); //MLSBundleUtils.parseFromBundle(bundle);MLSBundleUtils.createBundle(url)
instance.setData(initData);
if (!instance.isValid()) {
//illegal url
}
// remember to call the three life cycles of instance
instance.onResume();
instance.onPause();
instance.onDestroy();
Note:
- Remember to call the three life cycles of instance;
- The lua path is passed in the InitData initialization, and the project can run to display the corresponding lua interface.
- There will be an additional lua logo on the screen, we can use hot reload for more convenient development.
// 1. Set QrCaptureAdapter in the MLSEngine initialization. After setting, you can see an additional scan code icon in the lua floating window.
MLSEngine.init(mApplication, BuildConfig.DEBUG)
.setQrCaptureAdapter(new MLSQrCaptureAdapter() {
@Override
public void startQrCapture(Context context) {
//Jump to scan page
}
})
// 2. In the QR code scan result, set the hot reload mode to wifi connection
if (HotReloadHelper.isIPPortString(result)) {
HotReloadHelper.setUseWifi(result);
}
# Annotated and annotated classes are not confused
-keepattributes *Annotation*
-keepattributes Exceptions
-keep class com.immomo.mls.annotation.* { *; }
-keep @com.immomo.mls.annotation.LuaClass class * {
@com.immomo.mls.annotation.LuaBridge <methods>;
}
-keep @com.immomo.mls.wrapper.ConstantClass class * {
@com.immomo.mls.wrapper.Constant <fields>;
}
-keep,allowobfuscation @interface org.luaj.vm2.utils.LuaApiUsed
-keep @com.immomo.mls.annotation.CreatedByApt class * { *; }
-keep @org.luaj.vm2.utils.LuaApiUsed class *
-keep @org.luaj.vm2.utils.LuaApiUsed class * {
native <methods>;
@org.luaj.vm2.utils.LuaApiUsed <methods>;
@org.luaj.vm2.utils.LuaApiUsed <fields>;
}
(i) pod configuration:
pod 'MLN','1.0.0.2'
(ii) Environment configuration
// AppDelegate is set as follows
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// can be preloaded as needed
[MLNKitEnvironment instancePreload];
// set the default network handler
[MLNKitEnvironment setDefaultHttpHandler:...];
// set the default ScrollRefreshHandler
[MLNKitEnvironment setDefaultScrollRefreshHandler:...];
// set the default image loader
[MLNKitEnvironment setDefaultImageLoader:...];
// set the default navigation jump tool
[MLNKitEnvironment setDefaultNavigatorHandler:...];
}
(iii) Create a MLN Lua page
// Create a new .lua file in the project and name it demo.lua. Type the following lua code
label = Label()
label:setGravity(Gravity.CENTER)
label:text("Hello World!")
window:addView(label)
// then load demo.lua in the startup page
NSString *entryfile = @"demo.lua";
MLNKitViewController *kvc = [[MLNKitViewController alloc] initWithEntryFilePath:entryfile];
(iv) push page
[self presentViewController:kvc animated:YES completion:nil];
(v) After running, the device will display the lua file we loaded as above.
(i) pod configuration
pod 'MLNDevTool' , '0.1.8'
(ii) Create a MLN Lua page that supports HotReload
// create a Lua page
MLNHotReloadViewController *vc = [[MLNHotReloadViewController alloc] initWithNavigationBarTransparent:YES]
(iii) push page
[self presentViewController:vc animated:YES completion:nil];
(iv) Apply for camera permission
- Right click on the info.plist file-> Open As-> Source Code, add camera permissions.
<key>NSCameraUsageDescription</key> <string>我要使用摄像机</string>
- Right-click on the info.plist file-> Open As-> Property List and check if the camera permission is added successfully.
(v) After running, there will be an additional lua logo on the device screen. At this time, we can use hot reload for more convenient development.
Note:
- If the phone has a black screen, declare UIWindow in the AppDelegate.h file.
@property (strong, nonatomic) UIWindow *window;
- If you can't present the page, please check if the navigation controller is set.