当前位置: 首页 > 知识库问答 >
问题:

Android支持多索引库实现

任文乐
2023-03-14

我已经达到了magic dex的极限,因为我的应用程序使用了很多JAR(驱动API、greendao、文本到pdf、支持…)。

我目前的解决方案是,我只为google drive创建了第二个apk,我从主apk调用了它。但现在我发现android终于通过这个库支持了这一点。我的问题是我不知道如何实现它(最好没有gradle)。我找不到任何好的教程。

好吧,我正在失去理智,试图实现这个...我找到了这个

我补充说:

 android:name="android.support.multidex.MultiDexApplication"

到我的清单文件和

protected void attachBaseContext(Context base) {
     super.attachBaseContext(base);
     MultiDex.install(this);
}

我的主要活动。Java语言

还为eclipse安装了gradle插件,导出了gradle以获得构建。我更改为的gradle文件:

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':android-support-v7-appcompat')
    compile project(':Sync')
    compile project(':gdrive:google-play-services_lib')
}


android {
    compileSdkVersion 14
    buildToolsVersion "21.1.1"


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src-gen','src']
            resources.srcDirs = ['src-gen','src']
            aidl.srcDirs = ['src-gen','src']
            renderscript.srcDirs = ['src-gen','src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

    dexOptions {
      preDexLibraries = false
   }
}

afterEvaluate {
   tasks.matching {
      it.name.startsWith('dex')
   }.each { dx ->
      if (dx.additionalParameters == null) {
         dx.additionalParameters = ['--multi-dex']
      } else {
         dx.additionalParameters += '--multi-dex'
      }
   }
}

但误差仍然是一样的:(

共有3个答案

满博
2023-03-14

据https://developer.android.com/studio/build/multidex.html#avoid的医生说

如果你是minSdkVersion是21及以上,你需要做的就是

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

如果你的minSdkVersion是20或以下,你需要使用支持库

android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 25
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

随着

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>
慕容典
2023-03-14

有几件事你必须做,

1-在gradle中,您需要指定多索引并添加支持库:

android {
    defaultConfig {
        ...
        multiDexEnabled true
        ...
    }
}

dependencies {
  ...
  compile 'com.android.support:multidex:1.0.0'
  ...
}

2-在您的清单中,您必须将您的应用程序设置为multidex应用程序:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.package.name">
    <application
        ...
        android:name="com.package.name.my_application">
        ...
    </application>
</manifest>

3.1-在您的应用程序类中,您必须扩展MultiDexApplication

public class my_application extends MultiDexApplication
{
    ...
}

3.2-或在方法之外:

public class my_application extends Application
{
    protected void attachBaseContext(Context base)
    {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

multidex支持库的限制

multidex support library有一些已知的限制,当您将其纳入应用程序构建配置时,应该注意并测试这些限制:

  • 安装。在启动到设备的数据分区期间,dex文件很复杂,如果辅助dex文件很大,则可能导致应用程序不响应(ANR)错误。在这种情况下,您应该使用ProGuard应用代码收缩技术,以最小化dex文件的大小并删除代码中未使用的部分

资源:http://developer.android.com/tools/building/multidex.html

姚昊焱
2023-03-14

博客是旧的解决方案。

使用Android Studio 0.9.2

>

  • 添加到AndroidManifest.xml:

    .

    android:name="android.support.multidex.MultiDexApplication" 
    

    添加

    MultiDex.install(this);
    

    在自定义应用程序的attachBaseContext方法中

    或者您的自定义应用程序扩展多索引应用程序

    .

    android {
        defaultConfig {
            ...
            multiDexEnabled = true
        }
    }
    

    完成。

    对不起,我的英语很差

    相关资源:

    http://developer.android.com/tools/building/multidex.html

    https://plus.google.com/XavierDucrohet/posts/1FZWDCBNYC

  •  类似资料:
    • 我试图比较两个数据帧的差异,使用一个公共键/索引值,该值由帧中的3列组成。 e、 g.假设两列中的列都是:“COL1”、“COL2”、“COL3”、“COL4” 数据帧是df1 然后,我使用了set_index方法: 然后我想遍历df1数据帧,并检查df2数据帧是否有匹配的索引。我尝试过使用以下方法: 但是它返回false(尽管我可以通过打印看到两者的索引都存在)。 我做错了什么? 另外,如何使用

    • 您知道将引入Android支持库的计划吗?对于promise模式,它看起来是一个很好的解决方案。

    • 我尝试了所有我能在网上找到的解决方案,但没有任何帮助。以下是我尝试(在MAC OS X上)构建项目时遇到的错误: “/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:错误:执行任务检查DuplicateJavaLibraries:找不到文件”/Users

    • 问题内容: 当我运行该函数时,它会引发以下错误,这是为什么呢? 问题答案: 显然,您正在传递给函数。可能是用python2.x编写的(返回列表时)。使用python3.x时,返回一个行为更像a而不是a的对象。因此,无法对其进行索引。 解决方案是将(或简单地)传递给。

    • 问题内容: 我有这个查询: 我收到以下错误: some_id是一个整数,但我想选择具有some_id = 1的指标(或任何我决定放入变量的#)。 问题答案: 这会将参数转换为可索引的列表。假设您的方法像我想的那样工作,这应该工作。 发生错误是因为该方法中的某个地方,它可能试图遍历该输入或直接对其进行索引。可能是这样的: 通过使其成为列表(或可迭代的),您就可以像这样将其索引到第一个元素中。 您还可

    • 问题内容: 我正在设计一个将支持平板电脑的Android应用程序,但是我面临一个关于多屏支持的小问题。 谁能告诉我,下面的布局设计 我们在清单文件中指定以下代码。 现在将 ****如果布局如下,代码将保持不变; 定义是强制性的吗 ****在清单文件中? 如果我不定义怎么办。请帮我。 问题答案: Android开发教程 Android为具有数百种不同屏幕尺寸的数百种设备提供支持,从小型手机到大型电视