4 Replies Latest reply on Mar 8, 2013 12:22 AM by Gerbrand Stap

    Hardware acceleration on Android

    Gerbrand Stap

      Some canvas operations were not very smooth in our application, so I tried to improve performance and found a solution by turning on hardware acceleration.

      On the device we used this could be enabled using the Developer option to 'Force GPU rendering'. A nice solution for testing, but not for deployment. The way to enable hardware acceleration for an application is to add the attribute "android:hardwareAccelerated='true'" to the application tag in the application manifest (see: http://developer.android.com/guide/topics/graphics/hardware-accel.html). This file is generated with each build and can (according to the documentation) only be customized by editing the template (see: http://docs.rhomobile.com/rhodes/build#build-for-android, Customizing application’s AndroidManifest.xml). This template can be found in: <RhoMobile dir>\ruby\lib\ruby\gems\1.9.1\gems\rhodes-3.5.1.12\platform\android\Rhodes\AndroidManifest.xml.erb.

       

      This all works fine, but the problem is that these changes are lost when installing a new version of RhoStudio and we are working with multiple developers on the same project, so each developer has to make changes to his installation now and each time RhoStudio is updated. My question: Is there a way to define the android:hardwareAccelerated attribute in a RhoMobile project?

        • Re: Hardware acceleration on Android
          Robert Galvin

          Gerbrand

           

          It is not available via the build.yml at this time. One (not so ideal but may be better then modifying the source each time) is to have a 'dummy' native extension defined in your project that does not do anything. You can then following the detail on how to included modifications to the manifest via the native extensions:

           

          http://docs.rhomobile.com/rhodes/extensions#rewriting-the-generated-native-extension-source-code-for-android

           

          In the extensions ext.yml, you essentially specify a android manifest.xml file that will be merged with the one that comes from the rhodes source. be sure to include this 'native extension' on your build.yml so that it builds and includes it with your project. Then this way you can at least control including this at the project level.

           

          Hope this helps.

          Make changes to application AndroidManifest.xml

          You can specify changes to AndroidManifest.xml in the ext.yml file as a path to the files with the changes. There are three formats recognized by the build system, depending on the file extension:

          • .xml – xml file with common AndroidManifest.xml format; its tags will be merged into the final manifest.
          • .erb – ruby templates which will be injected into the final manifest.
          • .rb – ruby script which will run by manifest erb generator.

            android:

            manifest_changes: - ext/yourextension/platform/android/AndroidManifestAdds.xml - ext/yourextension/platform/android/ApplicationTagAdds1.erb - ext/yourextension/platform/android/ApplicationTagAdds2.erb - ext/yourextension/platform/android/ManifestTagAdds.erb - ext/yourextension/platform/android/AndroidManifestScript.rb 

          XML

          This is the simplest way, if you know how your manifest has to look. Add the final AndroidManifest.xml to the extension and specify it in ext.yml. The build system will try to merge all the tags from the file into the final AndroidManifest.xml. Tags which exist in both Rhodes and extension manifest will be overwritten from the extension manifest.

          android: manifest_changes: ext/yourextension/platform/android/AndroidManifest.xml 
          1 of 1 people found this helpful
            • Re: Hardware acceleration on Android
              Gerbrand Stap

              The extension method looks promising, but adding an extra attribute to the <application> tag does not seem to be possible. I've tried to merge the following xml to the manifest:

               

              <?xml version='1.0' encoding='UTF-8'?>
              <manifest xmlns:android='http://schemas.android.com/apk/res/android'>
                        <application android:hardwareAccelerated='true'>
                                  <service android:name='com.company.test'/>
                        </application>
                        <test>This is a test</test>
              </manifest>
              

               

              The file was referenced correctly in the ext.yml, because the resulting manifest contained the <service> and <test> tags, but the android:hardwareAccelerated attribute was missing.

               

              The ERB template and RB script methods both describe ways to add tags to the application or manifest tags, but there is nothing about adding attributes to these tags. So I assume that this is not possible and we have to edit the master template.