Android studio 调试错误 - 记录

1、Android Studio3.0以上,gradle.build中dependencie依赖由compile变为implementation  错误:

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

在App的build gradle 中:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile project(':SlidingMenulibrary')
}

将红色中的compile 改为 

implementation project(':SlidingMenulibrary')

2、Error:Could not find com.android.tools.build:gradle:3.1.2

问题原因:在以前的工程或则App 的bulid gradle 中

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'

    }
}

build.gradle 用的是  mavenCentral(); 而maven 中只有最高2.3.0

没有所需的2.3.3,所以,解决办法是:

不用mavenCentral , 改为用:jcenter(), 如下图:

buildscript {
    repositories {
        //mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'

    }
}

 

最后问题解决。

3、

错误:Program type already present: android.support.v4.app.BackStackRecord$Op 

错误:Program type already present: android.support.v4.app.ActionBarDrawerToggle$Delegate

两个错误的大致意思就是 前边已经存在了v4包的类文件。

看了一些博友的博客,发现我在配置

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.code.gson:gson:2.3.1'
    implementation project(':library-pulltorefresh')
    implementation 'com.mcxiaoke.volley:library:1.0.16'
    implementation project(':library-sidedrawer')
    implementation project(':library-circleimageview')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation project(':library-slidingmenu')
    implementation 'com.baoyz.swipemenulistview:library:1.3.0'
    implementation 'org.greenrobot:eventbus:3.0.0'
}
的时候 少了一个v4的导入(不加这个导入的话 ) 下面这行会报红线,但是不影响程序运行

  implementation 'com.android.support:appcompat-v7:27.1.1'  或则
  implementation 'com.android.support:support-v4:27.1.1'
加上这句话之后,以上问题 迎刃而解。

自己遇到,原因跟上面一样

Program type already present: android.support.v4.app.ActionBarDrawerToggle$SlideDrawable
Message{kind=ERROR, text=Program type already present: android.support.v4.app.ActionBarDrawerToggle$SlideDrawable, sources=[Unknown source file], tool name=Optional.of(D8)}

我的配置:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(':SlidingMenulibrary')
}

在Android Studio 中:解决方法:

点击菜单File -> Project Structure -> 弹出Moudle 管理窗口,

找到Dependencies - >  点击加号,增加App Modules 的v4 包,如下图:

5、org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed;

Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.

将所有的compile变为implementation 后,clean和rebuild都没有发现错误

6、错误: 程序包org.apache.http.protocol不存在

解决方法:

在app 工程中的build.gradle
在buildToolsVersion下边
defaultConfig上边

添加如下代码

    useLibrary 'org.apache.http.legacy'

 

6. Failed to load AppCompat ActionBar with unknown error.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>

to:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
</style>

7.intellij idea 报 Stub index points to a file without PSI

解决方法:

File > Invalidate Caches/Restart > Invalidate and Restart

 

 

 

### 如何在 Android Studio 中进行应用调试 #### 准备工作 为了能够在 Android Studio 中顺利地进行应用程序的调试,需要确保已安装最新版本的 Android Studio 和驱动程序。对于 USB 调试而言,还需确认设备上启用了开发者选项以及 USB 调试模式[^1]。 #### 设置 ADB 授权 当连接物理设备到电脑时,通常会弹出对话框请求允许来自计算机的调试权限。点击接受后,在命令行输入 `adb devices` 可查看当前连接的状态列表,以此验证设备是否被正确识别。 #### 配置项目运行配置 打开想要调试的应用工程文件夹下的 `.idea/runConfigurations/` 文件夹,找到对应的 XML 文件修改其中 `<option name="targetDevice">` 的值为目标模拟器或真实硬件名称;也可以直接通过图形界面设置&mdash;&mdash;依次选择菜单栏中的 "Run" -> "Edit Configurations..." 来完成相同操作[^2]。 #### 开始调试过程 - **启动调试**: 选中要执行的 Activity 或者整个 Application ,接着按下 Shift+F9 (Windows/Linux) / Cmd+Option+R (Mac),这将会编译并部署 APK 至选定的目标设备之上。 - **断点设定**: 在源码编辑区左侧空白处单击鼠标左键可快速添加断点位置,当程序流经此处便会暂停等待进一步指令。 - **变量监视与表达式求值**: 利用 Variables 窗口实时观察局部及全局范围内各个对象的变化情况;Watch Window 支持自定义计算任意合法 Java 表达式的即时结果。 - **线程跟踪**: Threads Pane 显示了所有正在活动的工作单元及其状态信息,有助于理解并发编程逻辑结构。 - **日志分析**: Logcat 是一个非常有用的工具面板,它能够捕获由应用程序产生的各种级别消息记录(Verbose, Debug, Info...),帮助定位潜在错误源头。 ```java // 示例代码片段展示简单的断点使用场景 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String testString = "Hello World!"; int number = calculateNumber(); // 断点可以设在这里 TextView textView = findViewById(R.id.textView); textView.setText(testString + ": " + number); } private int calculateNumber(){ return 4; // or any other logic here. } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值