我有一个最初用ADT编码的android项目,它有几个依赖于库项目和jar文件,如ActionBarSherlock和ViewPageIndicator,它在这一点上运行得很好,但我不得不转移到Android Studio并从中导出项目Eclipse生成gradle文件,经过一番努力才能使它构建,其中包括从使用它的几个库项目中删除android_support_v4.jar的使用,并在studio中创建一个依赖于android_support_v4的新空模块我的库依赖于它而不是我能够从Android Studio构建和运行项目到我的设备上,然而,一旦应用程序出现,它确实显示我的主要活动但它挂起并在几秒钟后我得到一个Out内存错误,并在堆栈跟踪中引用我的一个使用ActionBarSherlock的片段,但是我没有更改单个.java文件或任何其他源代码,它都是添加.gr adle和.iml文件并从我的库中删除android_support_v4.jar文件。
以下是主模块的build.gradle和settings.gradle文件:
的build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':JakeWharton-ActionBarSherlock-e5c2d1c:library')
compile project(':JakeWharton-ViewPagerIndicator-2.4.1-8cd549f:library')
compile project(':DevsmartLibrary')
compile project(':android-numberpicker:library')
compile project(':Android-Universal-Image-Loader:library')
compile project(':android-xmlrpc')
compile project(':StickyListHeadersLibrary')
compile project(':AndroidSupport')
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
settings.gradle:
include ':'
include ':AndroidSupport'
include ':android-numberpicker:library'
include ':JakeWharton-ViewPagerIndicator-2.4.1-8cd549f:library'
include ':android-xmlrpc'
include ':JakeWharton-ActionBarSherlock-e5c2d1c:library'
include ':StickyListHeadersLibrary'
include ':Android-Universal-Image-Loader:library'
include ':DevsmartLibrary'
我的虚拟模块AndroidSupport的 build.gradle 文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 15
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
}
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
我甚至不知道是不是要开始寻找,因为正如我所提到的,我没有更改任何源代码,任何指针都会非常感激。
编辑1: 如果它有任何帮助,这里是我的logcat的堆栈跟踪:
10-16 10:02:46.968: I/dalvikvm-heap(6323): Clamp target GC heap from 49.642MB to 48.000MB
10-16 10:02:46.968: D/dalvikvm(6323): GC_FOR_ALLOC freed 0K, 1% free 48713K/49159K, paused 322ms
10-16 10:02:46.968: I/dalvikvm-heap(6323): Forcing collection of SoftReferences for 272-byte allocation
10-16 10:02:47.328: I/dalvikvm-heap(6323): Clamp target GC heap from 49.642MB to 48.000MB
10-16 10:02:47.332: D/dalvikvm(6323): GC_BEFORE_OOM freed 0K, 1% free 48713K/49159K, paused 360ms
10-16 10:02:47.332: E/dalvikvm-heap(6323): Out of memory on a 272-byte allocation.
10-16 10:02:47.332: I/dalvikvm(6323): "main" prio=5 tid=1 RUNNABLE
10-16 10:02:47.332: I/dalvikvm(6323): | group="main" sCount=0 dsCount=0 obj=0x40a74460 self=0x11a2828
10-16 10:02:47.332: I/dalvikvm(6323): | sysTid=6323 nice=0 sched=0/0 cgrp=default handle=1074467976
10-16 10:02:47.332: I/dalvikvm(6323): | schedstat=( 0 0 0 ) utm=698 stm=41 core=0
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.Throwable.nativeFillInStackTrace(Native Method)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.Throwable.fillInStackTrace(Throwable.java:160)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.Throwable.<init>(Throwable.java:83)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.Error.<init>(Error.java:37)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.VirtualMachineError.<init>(VirtualMachineError.java:35)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.OutOfMemoryError.<init>(OutOfMemoryError.java:33)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:-1)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
10-16 10:02:47.332: I/dalvikvm(6323): at java.lang.StringBuilder.append(StringBuilder.java:216)
10-16 10:02:47.332: I/dalvikvm(6323): at com.my.project.containers.Banner.getImageUrl(Banner.java:57)
10-16 10:02:47.332: I/dalvikvm(6323): at com.my.project.fragments.BannerFragment.newInstance(BannerFragment.java:51)
10-16 10:02:47.332: I/dalvikvm(6323): at com.my.project.adapters.BannerItemFragmentPagerAdapter.getFragment(BannerItemFragmentPagerAdapter.java:143)
10-16 10:02:47.332: I/dalvikvm(6323): at com.my.project.adapters.BannerItemFragmentPagerAdapter.getItem(BannerItemFragmentPagerAdapter.java:92)
10-16 10:02:47.332: I/dalvikvm(6323): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:97)
10-16 10:02:47.332: I/dalvikvm(6323): at com.my.project.adapters.BannerItemFragmentPagerAdapter.instantiateItem(BannerItemFragmentPagerAdapter.java:111)
10-16 10:02:47.336: I/dalvikvm(6323): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:829)
10-16 10:02:47.336: I/dalvikvm(6323): at android.support.v4.view.ViewPager.populate(ViewPager.java:1044)
10-16 10:02:47.336: I/dalvikvm(6323): at android.support.v4.view.ViewPager.populate(ViewPager.java:911)
10-16 10:02:47.336: I/dalvikvm(6323): at android.support.v4.view.ViewPager.setOffscreenPageLimit(ViewPager.java:692)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.HomeFragment$BannersListener$1.run(HomeFragment.java:604)
10-16 10:02:47.336: I/dalvikvm(6323): at android.app.Activity.runOnUiThread(Activity.java:4170)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.HomeFragment$BannersListener.onBannerListLoaded(HomeFragment.java:582)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.projectd.models.BrowseModel.requestBanners(BrowseModel.java:605)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.HomeFragment$2.run(HomeFragment.java:390)
10-16 10:02:47.336: I/dalvikvm(6323): at android.app.Activity.runOnUiThread(Activity.java:4170)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.HomeFragment.updateUIForNetworkState(HomeFragment.java:378)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.HomeFragment.onNetworkStateChanged(HomeFragment.java:314)
10-16 10:02:47.336: I/dalvikvm(6323): at com.my.project.fragments.MyBaseFragment$NetworkStatusBroadcastReceiver.onReceive(MyBaseFragment.java:93)
10-16 10:02:47.336: I/dalvikvm(6323): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
10-16 10:02:47.336: I/dalvikvm(6323): at android.os.Handler.handleCallback(Handler.java:605)
10-16 10:02:47.336: I/dalvikvm(6323): at android.os.Handler.dispatchMessage(Handler.java:92)
10-16 10:02:47.336: I/dalvikvm(6323): at android.os.Looper.loop(Looper.java:137)
10-16 10:02:47.340: I/dalvikvm(6323): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-16 10:02:47.340: I/dalvikvm(6323): at java.lang.reflect.Method.invokeNative(Native Method)
10-16 10:02:47.340: I/dalvikvm(6323): at java.lang.reflect.Method.invoke(Method.java:511)
10-16 10:02:47.340: I/dalvikvm(6323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-16 10:02:47.340: I/dalvikvm(6323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-16 10:02:47.340: I/dalvikvm(6323): at dalvik.system.NativeStart.main(Native Method)
10-16 10:02:47.340: W/dalvikvm(6323): Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/OutOfMemoryError;)
10-16 10:02:47.652: I/dalvikvm-heap(6323): Clamp target GC heap from 49.641MB to 48.000MB
10-16 10:02:47.652: D/dalvikvm(6323): GC_FOR_ALLOC freed 1K, 1% free 48712K/49159K, paused 311ms
10-16 10:02:47.652: D/AndroidRuntime(6323): Shutting down VM
10-16 10:02:47.656: W/dalvikvm(6323): threadid=1: thread exiting with uncaught exception (group=0x40a731f8)
编辑2: 我没有尝试过Ray建议的内容,我只是将android:largeHeap =“true”添加到我的清单中,它不再因内存不足而崩溃,但仍然挂起然后ANR的
答案 0 :(得分:0)
我设法通过删除我在AndroidSupport包中提到的虚拟项目来修复此问题,我更改了对该库的所有引用:
compile project(':AndroidSupport')
到
compile 'com.android.support:support-v4:18.0.0'
由于某种原因,这次我没有得到我之前得到的错误:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/LoaderManager;
清理并重建所有内容后,应用程序现在运行得很好......