GithubHelp home page GithubHelp logo

smalldemo's Introduction

SmallDemo

创建工程

  • open Android Studio,点选 Start a new Android Studio project 创建一个Android工程。Application Name 本示例设置为 MySmall (您可以填写为自己的项目名称)。

集成Small

gradle.jpeg

	dependencies 
	{    
		classpath 'com.android.tools.build:gradle:2.2.3' //注意gradle版本号   
		classpath 'net.wequick.tools.build:gradle-small:1.1.0-alpha2'  
	} 
	
	//在文件末尾加上
	apply plugin: 'net.wequick.small'
	
	small 
	{
	    aarVersion = '1.1.0-alpha2'
	}

验证Small环境

在底部面板Terminal中输入命令:./gradlew small

如果一切正常,将成功输出:

  gradle-small plugin : 1.1.0-alpha2 (maven)
            small aar : 1.1.0-alpha2 (maven)
          gradle core : 3.3
       android plugin : 2.2.3
                   OS : Mac OS X 10.13.1 (x86_64)
type name PP sdk aapt support file(armeabi) size
host app 26 26.0.2 26.+
app app.main 0x77 26 26.0.2 26.+ *_main.so 43.7 KB

BUILD SUCCESSFUL

配置宿主

  • 新建Application,注入Small 新建Application.jpeg

  • 添加构造方法来初始化Small

public class SmallApp extends Application
{    
		public SmallApp() 
		{        
			Small.preSetUp(this);    
		}
}
  • 在AndroidManifest.xml 中指定这个 Application

创建插件模块

  • 右键 app 模块 > New > Module

创建一个应用模块 Phone & Tablet Module,设置 Application/Library name 为 App.main,此时 Module name 自动为 app.main,Package name 为 com.leo.smalldemo.app.main

  • 确认是否启动插件

修改插件的布局文件 app.main > res > layout > activity_main.xml,将 TextView 的内容改为 This is Small Model!

编译插件

  • 先编译公共库
./gradlew buildLib -q
  • 再编译app.main
./gradlew buildBundle -q -Dbundle.arch=x86

在模拟器调试时,-Dbundle.arch=xx,可以使用x86架构,真机打包时,需要使用到armeabi架构

启动插件

  • 右键 app 模块,New > Folder > Assets Folder 新建 assets 目录 assets目录.jpeg

  • 再右键生成的 assets 目录,New > File 新建路由配置文件 bundle.json: bundle.json

  • 修改bundle.json,添加路由

 {
  "version": "1.0.0",//文件格式版本,目前始终为1.0.0
  "bundles": [//插件数组
    {
      "uri": "main",//插件唯一ID
      "pkg": "com.leo.smalldemo.app.main"//插件包名
    }
  ]
}
  • 启动app.main插件

回到宿主的 app > java > com.leo.smalldemo > MainActivity, 在 onStart 方法中我们通过上述配置的 uri 来启动 app.main 插件:

 @Override
    protected void onStart() {
        super.onStart();
        Small.setUp(this, new Small.OnCompleteListener() {
            @Override
            public void onComplete() {
                Small.openUri("main",MainActivity.this);
            }
        });
    }

运行宿主

  • 在顶部菜单栏,我们先选择宿主模块 app,再点击旁边的运行按钮

run

  • 成功运行后,将启动插件模块:

succeed.jpg

smalldemo's People

Contributors

lexiaowen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.