一直纠结着这个错误,后来看别人的文章找到灵感,于是完善了基于cocos2dx2.1.5修改的

具体报错:JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal continuation byte 0xed

解决办法(基于coocs2dx2.1.5):

在CCImage.cpp里面的getBitmapFromJavaShadowStroke方法中,emjoy表情在jstring jstrText = methodInfo.env->NewStringUTF(text);

的时候触发崩溃,原因大致估计是因为emjoy不能被utf识别,于是绕过NewStringUTF,将之转化为byte[]来绕过.具体屏蔽jstring jstrText = methodInfo.env->NewStringUTF(text);修改为

 bool getBitmapFromJavaShadowStroke(   const char *text,int nWidth,int nHeight,CCImage::ETextAlign eAlignMask,const char * pFontName,float fontSize,float textTintR        = 1.0,float textTintG      = 1.0,float textTintB      = 1.0,bool shadow          = false,float shadowDeltaX         = 0.0,float shadowDeltaY       = 0.0,float shadowBlur         = 0.0,float shadowIntensity    = 0.0,bool stroke          = false,float strokeColorR         = 0.0,float strokeColorG       = 0.0,float strokeColorB       = 0.0,float strokeSize         = 0.0 ){JniMethodInfo methodInfo;if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxBitmap", "createTextBitmapShadowStroke","([BLjava/lang/String;IFFFIIIZFFFZFFFF)V")){CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);return false;}// Do a full lookup for the font path using CCFileUtils in case the given font name is a relative path to a font file asset,// or the path has been mapped to a different location in the app package:std::string fullPathOrFontName = CCFileUtils::sharedFileUtils()->fullPathForFilename(pFontName);// If the path name returned includes the 'assets' dir then that needs to be removed, because the android.content.Context// requires this portion of the path to be omitted for assets inside the app package.if (fullPathOrFontName.find("assets/") == 0){fullPathOrFontName = fullPathOrFontName.substr(strlen("assets/")); // Chop out the 'assets/' portion of the path.}/**create bitmap* this method call Cococs2dx.createBitmap()(java code) to create the bitmap, the java code* will call Java_org_cocos2dx_lib_Cocos2dxBitmap_nativeInitBitmapDC() to init the width, height* and data.* use this approach to decrease the jni call number*///jstring jstrText = methodInfo.env->NewStringUTF(text);/*** 修复emioy表情在android5.x以上系统jni崩溃bug* 将string修改为byte[].绕过jni在android5.x以上系统出现emjoy崩溃问题*/int strLen = strlen(text);jbyteArray byteArray = methodInfo.env->NewByteArray(strLen);methodInfo.env->SetByteArrayRegion(byteArray, 0, strLen, reinterpret_cast<const jbyte*>(text));jstring jstrFont = methodInfo.env->NewStringUTF(fullPathOrFontName.c_str());methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, byteArray,jstrFont, (int)fontSize, textTintR, textTintG, textTintB, eAlignMask, nWidth, nHeight, shadow, shadowDeltaX, -shadowDeltaY, shadowBlur, stroke, strokeColorR, strokeColorG, strokeColorB, strokeSize);methodInfo.env->DeleteLocalRef(byteArray);methodInfo.env->DeleteLocalRef(jstrFont);methodInfo.env->DeleteLocalRef(methodInfo.classID);return true;}

同时java对应修改传入参数

在Cocos2dxBitmap.java中,createTextBitmapShadowStroke传入参数修改为byte[]类型,然后将byte[]转化为string来正常直接emjoy的输出

public static void createTextBitmapShadowStroke(byte[] pString_byte,final String pFontName,final int pFontSize,final float fontTintR,final float fontTintG,final float fontTintB,final int pAlignment,final int pWidth,final int pHeight,final boolean shadow,final float shadowDX,final float shadowDY,final float shadowBlur,final boolean stroke,final float strokeR,final float strokeG,final float strokeB,final float strokeSize) throws UnsupportedEncodingException{/*** 将string修改为byte[].绕过jni在android5.x以上系统出现emjoy崩溃问题,然后重新转化为string来继续输出emjoy表情* @author lfy*/String pString=new String(pString_byte,"UTF-8");final int horizontalAlignment=pAlignment&0x0F;final int verticalAlignment=(pAlignment>>4)&0x0F;try{pString=Cocos2dxBitmap.refactorString(pString);}catch(java.lang.Exception e){}final Paint paint=Cocos2dxBitmap.newPaint(pFontName,pFontSize,horizontalAlignment);// set the paint colorpaint.setARGB(255,(int)(255.0*fontTintR),(int)(255.0*fontTintG),(int)(255.0*fontTintB));// modify some char error... s cdy20140731// final TextProperty// textProperty=Cocos2dxBitmap.computeTextProperty(// pString,pWidth,pHeight,paint);// final int bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight// :pHeight);TextProperty textProperty=null;int bitmapTotalHeight=0;textProperty=Cocos2dxBitmap.computeTextProperty(pString,pWidth,pHeight,paint);bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight:pHeight);if(bitmapTotalHeight<=0||textProperty.mMaxWidth<=0){textProperty=Cocos2dxBitmap.computeTextProperty(" ",pWidth,pHeight,paint);bitmapTotalHeight=(pHeight==0?textProperty.mTotalHeight:pHeight);}// modify some char error... e// padding needed when using shadows (not used otherwise)float bitmapPaddingX=0.0f;float bitmapPaddingY=0.0f;float renderTextDeltaX=0.0f;float renderTextDeltaY=0.0f;if(shadow){int shadowColor=0xff7d7d7d;paint.setShadowLayer(shadowBlur,shadowDX,shadowDY,shadowColor);bitmapPaddingX=Math.abs(shadowDX);bitmapPaddingY=Math.abs(shadowDY);if(shadowDX<0.0){renderTextDeltaX=bitmapPaddingX;}if(shadowDY<0.0){renderTextDeltaY=bitmapPaddingY;}}final Bitmap bitmap=Bitmap.createBitmap(textProperty.mMaxWidth+(int)bitmapPaddingX,bitmapTotalHeight+(int)bitmapPaddingY,Bitmap.Config.ARGB_8888);final Canvas canvas=new Canvas(bitmap);/* Draw string. */final FontMetricsInt fontMetricsInt=paint.getFontMetricsInt();int x=0;int y=Cocos2dxBitmap.computeY(fontMetricsInt,pHeight,textProperty.mTotalHeight,verticalAlignment);final String[] lines=textProperty.mLines;for(final String line:lines){x=Cocos2dxBitmap.computeX(line,textProperty.mMaxWidth,horizontalAlignment);canvas.drawText(line,x+renderTextDeltaX,y+renderTextDeltaY,paint);y+=textProperty.mHeightPerLine;}// draw again with stroke on if neededif(stroke){final Paint paintStroke=Cocos2dxBitmap.newPaint(pFontName,pFontSize,horizontalAlignment);paintStroke.setStyle(Paint.Style.STROKE);paintStroke.setStrokeWidth(strokeSize*0.5f);paintStroke.setARGB(255,(int)strokeR*255,(int)strokeG*255,(int)strokeB*255);x=0;y=Cocos2dxBitmap.computeY(fontMetricsInt,pHeight,textProperty.mTotalHeight,verticalAlignment);final String[] lines2=textProperty.mLines;for(final String line:lines2){x=Cocos2dxBitmap.computeX(line,textProperty.mMaxWidth,horizontalAlignment);canvas.drawText(line,x+renderTextDeltaX,y+renderTextDeltaY,paintStroke);y+=textProperty.mHeightPerLine;}}Cocos2dxBitmap.initNativeObject(bitmap);}

如此可以正常在聊天中输入emjoy表情了,如果有什么差错,麻烦指正下,个人QQ1908662823

关于emjoy表情在android5.x以上系统触发jni错误的修改(基于cocos2dx2.1.5修改)相关推荐

  1. Android5.0以上系统的移动网络开关

    笔者最近遇到一个非常有意思的bug,贴出来和大家分享下. 那是一个温暖的早晨,阳光晒得人很舒服.一封bug邮件像一片叶子飘到我的邮箱. 一番交流,笔者确认负责的Widget开关在Android5.0以 ...

  2. eomj表情 mysql_mysql 数据库支持emjoy表情

    数据库支持emjoy表情 对于emjoy表情,插入数据库的时候总是报错如下:Incorrect string value: '\xF0\x9F\x98\x8D' for column 'REAL_NA ...

  3. android 中限制 eidttext输入emjoy表情

    最近项目中遇到个不让Edittext输入Emjoy表情的需求,查找很多资料后最后用CSDN上一个哥们的方法解决 EditText et = (EditText)findViewById(R.id.et ...

  4. 高通平台开发环境搭建、编译、烧录(android5.1以上系统)

    高通平台开发环境搭建.编译.烧录(android5.1以上系统) 以MSN8937为例 1. 安装Ubuntu(12.04LTS以上稳定版本)     安装过程中必须以根用户登录或使用sudo获取ro ...

  5. 基于lbp算法的特征提取 表情识别和疲劳监测系统 matlab

    基于lbp算法的特征提取 表情识别和疲劳监测系统 matlab 情图片进行LPB+LPQ特征提取,最后放入支持向量机中分类训练,统计出训练和测试的精度 function varargout = uns ...

  6. 使用虚拟机安装Linux系统常见的错误以及解决方案

    使用虚拟机安装Linux系统常见的错误以及解决方案 参考文章: (1)使用虚拟机安装Linux系统常见的错误以及解决方案 (2)https://www.cnblogs.com/yanjiexiansh ...

  7. 关于系统弹出错误:429 , ActiveX 部件不能创建对象 的解决方法

    关于系统弹出错误:429 , ActiveX 部件不能创建对象 的解决方法 参考文章: (1)关于系统弹出错误:429 , ActiveX 部件不能创建对象 的解决方法 (2)https://www. ...

  8. 基于ubuntu16.04多用户编译android N(android 7.1)系统提示ninja_wrapper错误问题

    基于ubuntu16.04多用户编译android N(android 7.1)系统提示ninja_wrapper错误问题 Ubuntu 1604系统除了root,还有kandi和sundi两个用户, ...

  9. 彻底关掉win10自动更新_win10系统explorer.exe错误的解决教程

    小编给大家浅析win10系统explorer.exe错误的解决教程,电脑使用过程中,当你遇到电脑提示explorer.exe应用程序错误,导致桌面崩溃卡死的问题时,可参照以下的方法进行解决. 在我们日 ...

最新文章

  1. 【ACM】杭电OJ 1241(深度优先搜索小结)
  2. Python编码风格规范
  3. [转]tesseract OCR Engine overview字符识别学习
  4. DROP TABLE、TRUNCATE TABLE和DELETE的区别
  5. 【Java】蒙提霍尔问题的概率原理及随机化模拟
  6. todo项目开发_Facebook的TODO项目,巴西的Coursera,Drupal等
  7. 动态规划——最大子段和(洛谷 P1115)
  8. GitHub、YouTube 们的开源替代品都有了!
  9. c语言谱曲软件,基于C语言的音乐谱曲技巧与应用研究
  10. VBA实现多条件查询
  11. Yii使用 case when 来模糊排序查询
  12. 判断单链表是否有环及环的链接点(转)
  13. 二本电气工程应届生收割5个offer,转型大数据真的与专业无关
  14. python处理中文乱码现象
  15. PHP5.4 如何连接MS Sql Server
  16. 目前企业如何看待培训机构出来的程序员?
  17. 知衣科技:夫妻搭档,创业是件骨子里的事
  18. BITTER(蔓灵花)针对巴基斯坦和沙特阿拉伯发起了一波攻击
  19. PAT (Basic Level) Practise (中文) 1004成绩排名(20)
  20. 按要求编写一个Java应用程序:(1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。(2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性

热门文章

  1. 点击查看图片---弹窗直接显示图片并带关闭按钮
  2. 什么是应用服务器,有什么用?
  3. 平板电脑市场持续衰退,寄望二合一平板拯救该行业
  4. C语言网——【求[X,Y]内被除3余1并且被除5余3的整数的和】
  5. 【C语言】输入一个年份和月份,输出该月的天数
  6. vue 微信分享带图片,带title,带简介
  7. 第1章 SQL Server基本操作
  8. UsbDeviceManager.java
  9. RSD的面向对象分类设计
  10. 在python中用seaborn.boxplot画图,以及带子分组的并排箱线图