【问题标题】:Build a simple app using Sencha, not working on Android 4使用 Sencha 构建一个简单的应用程序,不适用于 Android 4
【发布时间】:2013-05-15 11:58:52
【问题描述】:

我希望有人帮助我验证我使用 Sencha Touch 和 Sencha Cmd 构建了一个简单的移动应用程序。

我一直在尝试构建一个 Android 应用程序,但我无法让它在 Android 4.0 模拟器或手机上运行,​​而且完全没有运气。

这就是我所做的。

第 1 步:创建一个新应用程序

Sencha generate app MyTouch22 ../projects/MyTouch22

此步骤会自动创建启动应用所需的所有文件夹和文件。它还生成了默认的 Main.js(主视图)。

第二步:修改打包文件(packager.json),使其符合Android 4.0(14级)如下图。

{
/**
 * @cfg  applicationName
 * @required
 * This is the name of your application, which is displayed on the device when the app is installed. On IOS, this should match
 * the name of your application in the Apple Provisioning Portal.
 */
"applicationName":"My Touch22",

/**
 * @cfg  applicationId
 * This is the name namespace for your application. On IOS, this should match the name of your application in the Apple Provisioning Portal.
 */
"applicationId":"com.test.mytouch22",

/**
 * @cfg  versionString
 * @required
 * This is the version of your application.
 */
"versionString":"1.0",

/**
 * @cfg  versionCode
 * @required
 * This is the integer version code of your application, or you can refer to it as a build number. Used only for Android builds.
 */
"versionCode":"1",

/**
 * @cfg  icon
 * For iOS, please refer to their documentation about icon sizes:
 * https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html
 *
 * For Android, please refer to the Google Launcher icons guide:
 * http://developer.android.com/guide/practices/ui_guidelines/icon_design_launcher.html
 * iOS uses 57, 72, 114 and 144; Android uses 36, 48 and 72; if you package for Android you can ignore iOS icons and vice verca
 */
"icon": {
    "36":"resources/icons/Icon_Android36.png",
    "48":"resources/icons/Icon_Android48.png",
    "57":"resources/icons/Icon.png",
    "72":"resources/icons/Icon~ipad.png",
    "114":"resources/icons/Icon@2x.png",
    "144":"resources/icons/Icon~ipad@2x.png"
},

/**
 * @cfg  inputPath
 * @required
 * This is location of your Sencha Touch 2 application, relative to this configuration file.
 */
"inputPath":"./",

/**
 * @cfg  outputPath
 * @required
 * This is where the built application file with be saved. Make sure that output path is not in your input path, you may get into endless recursive copying 
 */
"outputPath":"c:\\Apps\\build\\",

/**
 * @cfg  configuration
 * @required
 * This is configuration for your application. `Debug` should always be used unless you are submitting your app to an online
 * store - in which case `Release` should be specified.
 */
"configuration":"Debug",

/**
 * @cfg  platform
 * @required
 * This is the platform where you will be running your application. Available options are:
 *  - iOSSimulator
 *  - iOS
 *  - Android
 *  - AndroidEmulator
 */
"platform":"AndroidEmulator",


/**
 * @cfg  certificatePath
 * This is the location of your certificate.
 * This is required when you are developing for Android or you are developing on Windows.
 */ 
"certificatePath": "C:\\Sencha Architect\\keystore\\test-mytouch22.keystore",


/**
 * @cfg  sdkPath
 * This is the path to the Android SDK, if you are developing an Android application.
 */
"sdkPath": "C:\\Android Development\\adt-bundle-windows-x86_64-20130219\\sdk",  

/**
 * @cfg  androidAPILevel
 * This is android API level, the version of Android SDK to use, you can read more about it here: http://developer.android.com/guide/appendix/api-levels.html.
 * Be sure to install corresponding platform API in android SDK manager (android_sdk/tools/android)
 */
"androidAPILevel":"14",

    /**
 * @cfg {Array[String]} permissions
 * Array of permissions that is used by an application (Android only) 
 * Full list of permissions for Android application can be found here: http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_CHECKIN_PROPERTIES
 */
"permissions":[
        "INTERNET"
    ],

/**
 * @cfg {Array[String]} orientations
 * @required
 * This is orientations that this application can run.
 */
"orientations": [
    "portrait",
    "landscapeLeft",
    "landscapeRight",
    "portraitUpsideDown"
]
}

第 3 步:构建应用到 APK 文件

sencha app package build packager_android.json

第 4 步:运行我的 android 4.0 模拟器

android -avd Android_4_Phone

第 5 步:将 APK 文件安装到模拟器中

adb install MyTouch22.apk

按照我上面提到的步骤,我卡在加载屏幕上。当我为 Android 3.0(级别 11)重新执行整个过程并使用 Android 模拟器时,它可以工作文件。但是,当我将工作版本的 APK 文件(Android 3.0)部署到 Android 4.0 模拟器时,我在加载页面遇到了同样的问题。

我使用的工具是 Sencha Touch 2.2 和 Sencha Cmd 3.1.1.274。

文档/来源:

  1. http://docs.sencha.com/touch/2.2.0/#!/guide/native_packaging
  2. http://docs.sencha.com/touch/2.2.0/#!/guide/command_app

【问题讨论】:

  • 我一直使用phonegap编译到android,从来没有问题。你已经试过了吗?您也可以下载 sdk for android 并查看调试(控制台和 msg javascripts 工作),非常好调试。
  • 将 API 级别更改为 7 .. 尝试命令 sencha app build native
  • 卡在初始白屏?我遇到了同样的问题,而且这只发生在 Android 4.0 上。不知道为什么..顺便说一句,只需尝试将 API 级别更改为 15 看看会发生什么..如果您看到任何进展,请回复我们..
  • @Harikrishnan sencha app build native 只构建代码,您可以在您的网络浏览器上运行,并且该部分使用 API 级别 14 工作。我需要打包代码以部署代码到 Android 模拟器和手机,这是进程失败的时候。
  • @donny 你错了。 sencha app build native 为 Android、iPhone、Blackberry 构建原生代码。我正在使用这个。

标签: android-emulator sencha-touch sencha-cmd


【解决方案1】:

我建议您按照以下步骤制作一个测试应用程序,如果您在任何步骤中遇到错误,请将错误粘贴给我。

1)`sencha generate app Appname ../Appname`
2)open ../Appname and do ur code..make it 100% working on browser
3)open packager.json and fill the necessary fields..the comment shows how to fill it
4)change API level to 7 in it.
5)install android sdk in ur computer and assign it to `sdkPath` variable
6)cd to app directory (Appname)
7)compass compile resources/saas
(Here you have to install ruby if its not installed, just search with the error in google you will get solution)
8)then `sencha app build native`

它会将apk文件部署到Appname/build/Appname/native

【讨论】:

  • 感谢您的分步说明。这些有很大帮助。我现在开始工作了。我只想在步骤 #7 compass compile resources/sass 中对上面的说明进行一个小修正
  • 我听不懂..你能解释一下吗? (顺便说一句,compass compile 将在 build 时已经执行..它不需要..如果没有安装 ruby​​/gem,我已经给出了这个步骤来向您展示确切的错误)。
  • 好的。但是,它也帮助我找出了我的错误。显然,即使 Sencha Cmd 3.1.1 假设与 Ruby 1.9.xx 一起提供,但当我执行构建过程时,它无法自动运行 ruby​​。
  • @Harikrishan:我有一个疑问,我已经从 sencha touch 项目成功生成了 android apk,不幸的是,当我在 android 设备或模拟器中运行该应用程序时,只显示启动图像,没有任何反应,是需要服务器运行,以便应用程序可以从 sencha touch 项目中获取内容? ,因为我在 sencha touch 中浏览了一些示例,他们使用 xampp 作为本地服务器来运行浏览器。
  • 如果您不使用后端网络服务,则不需要网络服务器来运行 sencha 应用程序。这只是javascript。尝试从任何示例项目中制作 apk 并在移动设备中运行它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-11
  • 2011-04-06
  • 1970-01-01
  • 2019-12-17
  • 2016-06-23
  • 1970-01-01
相关资源
最近更新 更多