黑科技:使用AI和机器学习将Android项目秒变IOS项目

6098829-ca5e271381e374c6.png

最近看Github,发现了一个刚出炉的黑科技:利用人工智能(AI)和机器学习(ML)技术将现有Android源代码转换成iOS代码。目前支持Android项目中的资产目录文件和UI布局转换,以及部分外部库的转换。有了这个神器,以后一个人就可以轻松搞定两个平台了,真是爽歪歪啊。。。。我根本不需要学习iOS了。。。


已支持的功能:

  1. Android的资产目录 (如:jpgpng.9图等) => "Assets.xcassets"
  2. mipmap目录的图片资源 => “.appiconset”
  3. Color形式的xml => “.colorset”
  4. Shape形式的xml => PDF format in asset catalog
  5. Vector形式的xml文件 => Swift Code (CAShapeLayer)
  6. Animation形式的xml文件
  7. UI布局的xml文件 => storyboard file
  8. Java的POJO类 => Swift
  9. 外部的库Glide的转换

正在开发中的功能:

  1. 资源(Resource)xml文件
  2. Android SDK的类
  3. 更多的外部的库,比如:GSON, Retrofit2, ButterKnife等。
  4. 矢量图动画(Vector Animation)xml资源

未来支持的功能:

  1. Android的Kotlin语言
  2. Android的JetPack
  3. Android的代码编写的布局 转成 SwiftUI
  4. Lagacy .storyboard 转成 SwiftUI
  5. 测试用例的生成

UI的转换

目前支持CardView,Switch,ImageButton,ToggleButton这些控件类型的转换。

部分效果图如下:

CardView的屏幕截图:

6098829-e43a62a4bed4c55d
image

开关,ImageButton,ToggleButton的屏幕截图:

6098829-89e788b85099bb9c
image

Button的屏幕截图:

6098829-6d6b4985c487df36
image

TextView的屏幕截图:

6098829-aa028b0143413d00
image

使用普通键盘的EditText的屏幕截图:

6098829-88accf1cec646483
image

带电话拨号键盘的EditText的屏幕截图:

6098829-f8978290658cd6d2
image

布局的转换

目前支持RelativeLayout,FrameLayout,LinearLayout (Nested),ConstraintLayout,TableLayout和ScrollView这些布局类型的转换。另外只有部分布局属性做了转换,如下表所示:

Control Attributes
LinearLayout orientation, gravity, background, textAppearance
RelativeLayout layout_centerHorizontal, layout_centerVertical, layout_toLeftOf, layout_toRightOf, layout_above, layout_below, layout_alignParentTop, layout_alignParentBottom, layout_alignParentRight, layout_alignParentLeft
FrameLayout layout_marginTop, layout_gravity = right, left, right+bottom, left+bottom, center, center_horizontal, center_vertical, right+center_vertical, bottom+center_horizontal
ConstraintLayout Bottom_toBottomOf, Top_toTopOf, Top_toBottomOf, Left_toLeftOf, Start_toEndOf, Right_toRightOf, Baseline_toBaselineOf, Vertical_bias, Horizontal_bias
TableLayout TableLayout, TableRow, background, padding
ScrollView ScrollView, android.support.v4.widget.NestedScrollView, HorizontalScrollView, android:scrollbars

LinearLayout的屏幕截图:

6098829-c518f6de738fe7cf
image

6098829-cfd01acf7830b175
image

RelativeLayout的屏幕截图:

6098829-e0b47b805b7b8195
image

6098829-ecbfb8b0b29b1690
image

FrameLayout的屏幕截图:

6098829-18ffd96785021c00
image

6098829-4d94804cff6b8d2d
image

ConstraintLayout的屏幕截图(这个也做了移植,确实经惊艳到我了):

6098829-1f740355ad230444
image

6098829-c9848131b12a4cde
image

TableLayout的屏幕截图:

6098829-40e674ca9e0cb78f
image

6098829-811d704d5ad206e5
image

ScrollView的屏幕截图:(gif图内容太大,做了压缩)

6098829-ae83d3263a2b018d.gif

资产目录文件的转换

这一部分内容比较多,简单的说就是把Android工程的res目录的文件转换成iOS工程的Assets.xcassets目录的文件。

  • mipmap目录的图片资源:Android工程的mdpi,hdpi,xhdpi和xxhdpi的图像资源被映射到iOS工程的1x,2x和3x图像资源路径里面。

  • 针对.9.png图片文件:在catalog中为asset添加了切片(slicing )信息。

  • Vector图片形式的xml被转换成Storyboard上能够使用的.pdf文件。

  • 向量图像xml也被转换成Swift代码,并在VectorStore.swift中为每个vector文件添加一个静态方法。

除此之外还支持.png,color形式的xml,Shape形式的xml,Animation形式的xml的转换。


以下是使用截图:

Android和iOS设备的显示了各种资产的使用情况的屏幕截图:

6098829-80266053fdd56516
image

Android Studio布局编辑器:

6098829-01539d7d935afcd6
image

Xcode Storyboard编辑器:

6098829-88a672e1bfbf9596
image

Android Studio Asset资源图片:

6098829-b867eb2f5b2ed6ac
image

Xcode Asset 面板:

6098829-2e2ff5838b0d5782
image

Android Studio .9.PNG 图片资源编辑器:

6098829-b4d3f92d2c971090
image

Xcode Asset面带有从.9.png文件中提取的切片信息:

6098829-90a3a30ea8b1eb97
image

Vector矢量图的转换截图对比:

6098829-32510095f4835bd7
image

Shape xml文件的对比:

6098829-d56228d247424325
image

动画转换的对比:

Android iOS
6098829-f7f2705e71f00dd5.gif
6098829-b928c6a854aaac4e.gif

事实上效果是同步的,只是录屏和操作步骤不一致的原因,看起来有些延迟。


外部库Glide的转换

支持的功能:

  • 从本地res文件夹加载drawable
  • 从URL加载图片
  • 将图片加载到UIImageView
  • 在下载过程中提供占位符图片
  • 在图片之间应用过渡:CrossFade,Flip
  • 支持图片Transformation (变换)API:circleCrop(),centerCrop(),fitCenter(),centerInside()
  • 清除待处理的请求
  • RequestOptions类可在实例之间重用设置

待支持的API:

  • priority()
  • diskCacheStrategy()
  • asBitmap()
  • error()
  • fallback()
  • clearMemory()

使用截图:

6098829-b246286cf40a68cd
image

计算器App

这是一个移植的计算器项目。

使用截图如下,还是挺酷选的呢,效果保持一致,操作也很流畅:

6098829-3425db5437ae33d2
image

最后附上官网地址,有兴趣的可以去看看。

官网地址:http://www.reflectcode.com/

Github: https://github.com/ReflectCode/

发布了125 篇原创文章 · 获赞 19 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/lzw2497727771/article/details/103576870