Android ionic 使用当中的几个问题记录

问题1:@ionic/app-scripts not installed

解决: 在项目目录下安装:npm install @ionic/app-scripts@latest --save-dev

问题2:Cannot read property 'type' of undefined

完整的错误信息如下
Error: ./node_modules/tslib/tslib.es6.js
Module build failed: TypeError: Cannot read property 'type' of undefined

解决:这个问题和第一个问题的解决方式一样, 在项目目录下安装:npm install @ionic/app-scripts@latest --save-dev

问题3:CordovaError: Requirements check failed for JDK 1.8 or greater

JDK版本过高了

解决:如果你同时安装了1.8和更高的版本,不需要卸载较高的版本,只要在环境变量中的用户变量中设置你的JAVA_HOME的路径对应到你的1.8版本就行了。

环境变量修改.png

问题4:Failed to execute aapt

这个问题其实是FileOpener2插件引起的,因为这个插件使用的V4包没有指定具体的版本号。
我们可以再生成的Android项目的App的gradle中看到

v4+.png

修改为具体的版本后,build成功。
v4.png

解决:这个是FileOpener2的问题,在这个插件的plugin.xml 文件里修改
<framework src="com.android.support:support-v4:+" />

<framework src="com.android.support:support-v4:27.1.1" />

问题5:自定义插件调用失败

提示ng:///AppModule/StatisticsPage.ngfactory.js: Line 392 : ERROR

对比可以调用的插件中的www文件夹中的js文件,发现文件头有一行重复,多了一层,删除这层。 www是指生成Android目录中的asset文件夹中的


image.png

问题6:线程问题

默认不是在主线程当中的,如果你要操作activity,需要再主线程当中

Threading

The plugin's JavaScript does not run in the main thread of the WebView interface; instead, it runs on the WebCore thread, as does the execute method. If you need to interact with the user interface, you should use the Activity's runOnUiThread method like so:

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if ("beep".equals(action)) {
        final long duration = args.getLong(0);
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                ...
                callbackContext.success(); // Thread-safe.
            }
        });
        return true;
    }
    return false;
}

If you do not need to run on the UI thread, but do not wish to block the WebCore thread either, you should execute your code using the Cordova ExecutorService obtained with cordova.getThreadPool() like so:

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if ("beep".equals(action)) {
        final long duration = args.getLong(0);
        cordova.getThreadPool().execute(new Runnable() {
            public void run() {
                ...
                callbackContext.success(); // Thread-safe.
            }
        });
        return true;
    }
    return false;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,107评论 19 139
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,486评论 0 10
  • 1.A simple master-to-slave replication is currently being...
    Kevin关大大阅读 6,042评论 0 3
  • Six 水月和启昊不在同一个学校,所以不能每天相见。即使两个人的联络仅限于每日放学后短暂的电话,但水月还是很踏实。...
    _文觉阅读 839评论 1 4
  • 依旧喜欢发微笑的表情,依旧喜欢踩着滑板追逐着夕阳,依旧喜欢吹着海风听着海浪声,依旧喜欢看雨在城市中狂欢。这一圈又一...
    君霏逸阅读 115评论 0 0