2016-10-04 136 views
8
没有找到可执行代码

我正在开发一个Android应用程序使用Android Studio 2.1.3和gradle。Android工作室gradle断点在行

问题是,一个简单方法中的断点从来没有命中,但它必须被命中,因为在应用程序调试过程中满足条件。
首先,我认为这个问题是关系到答案为这个问题所描述的问题: BuildConfig.DEBUG always false when building library projects with gradle

为了测试这一点,我删除库项目和综合我所有的源代码,进入主应用程序模块。它什么也没解决。 要注意的是,以下是的build.gradle,在缩小设置为false两种调试/发布:

apply plugin: 'com.android.application' 
 

 
android { 
 
    compileSdkVersion 23 
 
    buildToolsVersion "23.0.2" 
 
    defaultConfig { 
 
     applicationId "com.mycompany.mymobileapp" 
 
     minSdkVersion 21 
 
     targetSdkVersion 21 
 
     versionCode 1 
 
     versionName "1.0" 
 
    } 
 
    buildTypes { 
 
     release { 
 
      minifyEnabled false 
 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
 
      debuggable true 
 
      jniDebuggable true 
 
      renderscriptDebuggable true 
 
      zipAlignEnabled false 
 
     } 
 
     debug { 
 
      debuggable true 
 
      minifyEnabled false 
 
      zipAlignEnabled false 
 
      jniDebuggable true 
 
      renderscriptDebuggable true 
 
     } 
 
    } 
 
    productFlavors { 
 
    } 
 
} 
 
    
 
dependencies { 
 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
 
    testCompile 'junit:junit:4.12' 
 
    testCompile 'org.mockito:mockito-core:2.0.5-beta' 
 
    testCompile 'com.android.support:support-v4:23.1.1' 
 
    testCompile 'org.powermock:powermock-api-mockito:1.6.2' 
 
    testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.2' 
 
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.2' 
 
    testCompile 'org.powermock:powermock-module-junit4:1.6.2' 
 
    compile 'com.android.support:appcompat-v7:23.1.1' 
 
}

这里是什么样的Android Studio显示我的截图:

No executable code found problem

这也并不是唯一的案例。碰巧,编译器在Stepping结束时跳转到代码的另一部分,而不是被调试的部分。

这里有什么合理的解释吗? 暂停:尝试“线程”和“全部”,结果相同。

UPDATE 1: 使用Eclipse重新创建项目,并且一切正常。 为什么使用Android工作室这是不行的!

回答

6

使用Eclipse重新创建应用程序并观察正确的行为后,我返回到Android Studio以检查是否有任何我错过的选项。

从File - > Settings中尝试了所有选项后,我得出结论Instant Run是造成我浪费如此多宝贵时间的邪恶。

我不明白它是如何与我的问题有关,但清除所有检查盒后:

enter image description here

我结束了执行我作为一个开发者所期望的方式代码:

enter image description here

+0

这不是解决这个问题的方法......即时运行在大多数情况下都很有效。你浪费你的时间只是因为你不知道当你在任何编辑器遇到这个问题时,干净始终是第一选择,这是众所周知的。但是我想知道是否有这方面的错误报告,或者是因为它会驱动我的坚果,即使它每周只发生一次。 – Renetik

+0

在我的情况下,它一直在发生。你想和C,C++,C#和Java等许多编辑和6年的经验争论,并告诉我,我不知道如何清理一个项目?请不要再写这些无用的评论。可悲的是我不能向你投票评论。另外,这不会发生在我身上。此后与许多其他全职Android开发人员一起讨论,并且由于这样的错误,他们默认立即关闭。 – XMight

+0

好,所以你清理项目和brakpoint仍然没有奏效?所以这是另一个问题,因为在即时运行打开的情况下,这种情况从来没有发生过,并且我在测试版发布后使用它。你没有提到你一次在你的回答和问题中清理过项目,所以我的评论怎么没用。投票,但是你想要的。那就是它的用途。 – Renetik

0

尝试清理和重建项目。 尝试在这个方法中做一些日志来检查它是否被执行。

LOG.(TAG,"method being executed") 
+0

清洁是一个很好的解决方法,但是这个错误报告在哪里,我应该投票解决?我必须等待4分钟后,我打了干净,这不是太多的即时运行。 – Renetik

8
buildTypes { 

release { 
    minifyEnabled true 
    shrinkResources true 
    proguardFiles getDefaultProguardFile('proguard-android.txt') 

} 
debug { 
    debuggable true 
    minifyEnabled false 
    proguardFiles getDefaultProguardFile('proguard-android.txt') 

} 

}

设置minifyEnabled false在build.gradle文件的调试块中。

+0

工作。只需添加清洁和生成。干杯@vinod – ralphgabb

2

我正面临类似的问题。

我已经试过:

  • 清洁项目
  • 重置Android Studio中
  • 重建项目
  • 禁用即时运行

,并没有奏效。

所有我最后还是没让它工作是按Ctrl ++ + 。这是扩展所有代码块的捷径。之后我刚刚运行了该项目,并且工作正常。

+1

做了同样的事情,没有任何帮助。 -_-疯狂。 – garbus