在Gradle构建的dexOptions中,jumboMode的用途是什么?

时间:2015-08-18 08:22:47

标签: android gradle

根据this post,它允许dex文件中包含更多字符串,但我并不真正理解它的含义以及对构建的影响。

2 个答案:

答案 0 :(得分:2)

  

Jumbo模式与可引用的字符串数有关   DEX文件,默认情况下使用16位宽整数进行索引。   因此,如果您的应用程序编码超过2 ^ 16个字符串,则为dx   工具也会失败。但是对于字符串引用,有一个   补救措施:DEX支持“jumbo操作码”,允许32位宽   字符串引用。 Android Gradle构建中的jumboMode标志   脚本启用此模式,允许最多2 ^ 32个字符串   引用。

这意味着如果你的dex文件中有超过2 ^ 16个引用,你可以使用<Window x:Class="VenProp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:VenProp" xmlns:sphere="clr-namespace:VenProp.Sphere3D" mc:Ignorable="d" Title="VenProp" Height="{Binding Source={x:Static SystemParameters.PrimaryScreenHeight}, Converter={local:RatioConverter}, ConverterParameter='0.9' }" Width="{Binding Source={x:Static SystemParameters.PrimaryScreenWidth}, Converter={local:RatioConverter}, ConverterParameter='0.9' }" WindowStartupLocation="CenterScreen" Background="#FFE4E4E4"> <!-- Window Resources --> <Window.Resources> <sphere:SphereMeshGenerator x:Key="SphereGeometrySource"/> <MeshGeometry3D x:Key="SphereGeometry" Positions="{Binding Source={StaticResource SphereGeometrySource}, Path=Geometry.Positions}" TriangleIndices="{Binding Source={StaticResource SphereGeometrySource}, Path=Geometry.TriangleIndicies}" TextureCoordinates="{Binding Source={StaticResource SphereGeometrySource}, Path=Geometry.TextureCoordinates}"/> </Window.Resources> <!-- Overall Container is VERTICAL--> <DockPanel> <!-- Top Menu --> <Menu DockPanel.Dock="Top" HorizontalAlignment="Left" BorderBrush="Black"> <MenuItem Header="_File"></MenuItem> </Menu> <!-- Main toolbar --> <ToolBar DockPanel.Dock="Top"> <Button> <!-- Put image here--> </Button> <Button Content="Button2"/> </ToolBar> <!-- StatusBar --> <StatusBar x:Name="statusBar" DockPanel.Dock="Bottom" /> <!-- Inner container is horizontal --> <DockPanel> <Separator Width="2" Foreground="{x:Null}" Background="{x:Null}"/> <!-- Throw Tree into a dock panel with its label--> <StackPanel Width="310" DockPanel.Dock="Left" HorizontalAlignment="Left" Margin="0,0,0,2" Background="#FFE4E4E4"> <Label Content="Object Browser" FontSize="12" Background="LightGray"/> <TreeView x:Name="ObjectBrowser" BorderThickness="2" Height="620" DockPanel.Dock="Top"> <TreeView.BitmapEffect> <BevelBitmapEffect BevelWidth="5" Relief="0.4" LightAngle="320"/> </TreeView.BitmapEffect> </TreeView> </StackPanel> </DockPanel> <Separator Width="10" Background="{x:Null}" Foreground="{x:Null}" RenderTransformOrigin="-0.45,0.541" /> <!-- Tabs for graphics windows --> <TabControl x:Name="tabGraphics" BorderThickness="5"> <TabControl.BitmapEffect> <BevelBitmapEffect BevelWidth="15" Relief="0.4"/> </TabControl.BitmapEffect> <!-- 3D Earth Model --> <TabItem x:Name="graphics3D" Header="3D Graphics"> <DockPanel Background="Black"> <Viewport3D x:Name="mainScene3D"> <!--Camera--> <Viewport3D.Camera> <PerspectiveCamera x:Name="mainCam" LookDirection="-1,0,0" Position="5,0,0" UpDirection="0,1,0"/> </Viewport3D.Camera> <!--Earth Model--> <ModelVisual3D> <ModelVisual3D.Content> <Model3DGroup> <AmbientLight Color="White"/> <GeometryModel3D Geometry="{StaticResource SphereGeometry}"> <GeometryModel3D.Material> <MaterialGroup> <DiffuseMaterial> <DiffuseMaterial.Brush> <ImageBrush ImageSource="H:\C#\VenProp\VenProp\Images\Earth.jpg"/> </DiffuseMaterial.Brush> </DiffuseMaterial> </MaterialGroup> </GeometryModel3D.Material> </GeometryModel3D> </Model3DGroup> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D> </DockPanel> </TabItem> <TabItem x:Name="graphics2D" Header="2D Graphics"> <DockPanel Background="Gray"> <Image Source="H:\C#\VenProp\VenProp\Images/Earth.jpg"/> </DockPanel> </TabItem> </TabControl> </DockPanel> </Window> 来容纳这个,最多允许2 ^ 32个引用。这是通过强制字节代码始终使用&#34; jumbo strings&#34;来完成的。 (2 ^ 32)引用有助于避免在合并dex文件时出现问题。

注意:这与方法引用的数量无关,因此当dex文件的方法超过64k时,此模式无法解决。

来源:https://developers.soundcloud.com/blog/congratulations-you-have-a-lot-of-code-remedying-androids-method-limit-part-1

根据我的经验,除了可能会增加构建时间之外,这不会对构建产生任何明显的影响。

答案 1 :(得分:0)

在android中编译代码时,您的java代码将被编译为.dex文件。

对dex文件中可以存在的字符串数有限制。通过启用 jumboMode ,可以增加dex文件中可以存在的字符串数。

从Gradle 2.1.0开始,

jumboMode选项为true,因此您不必为此担心

相关问题