android studio 问题,Android Studio 常见问题

本文详细介绍了如何在Git中处理未跟踪分支,包括切换到新分支并设置远程跟踪,重命名和删除远程分支,以及为本地和远程分支打tag。还涵盖了Android Studio中构建APK文件的命名规则和常见编译问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用 Git

1. Can't update: no tracked branch

复现场景: 假设当前工作环境的 local 分支是 local-v1-dev,然后通过删除了这个分支,并 check out 到了另一个分支 local-v2-dev 上去,然后使用 pull 操作拉取远程 remote 分支代码时出现问题。

8c95d76f5edf?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

解决措施: 假设需要切换新的本地分支名称为newBranch,需要拉去远程的 newBranch 分支,并执行更新操作,通过使用Android Studio 的 终端 Terminal 工具,执行下面的命令让本地分支和远程分支完成匹配即可。

git checkout newBranch

git branch --set-upstream-to=origin/newBranch

2. 重命名远程分支

在git中重命名远程分支,其实就是先删除远程分支,然后重命名本地分支,再重新提交一个远程分支。

先查看远程分支:

使用 git branch 命令可以查看当前所有本地分支,加上 -a 参数可以查看远程分支,远程分支会用红色表示出来:

git branch -a

8c95d76f5edf?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

删除远程分支和 tag:

a. 删除指定的远程分支(把 替换成要删除掉的分支名称)

git push origin --delete

b. 删除指定的tag(把 替换成要删除掉的tag名称)

git push origin --delete tag

在 github 上操作时,在删除远程分支时有可能碰到下面这个错误:

remote: error: refusing to delete the current branch:

这是由于在 github 中,被删除的分支是项目的默认分支。要解决此问题,需要进行下面的操作:

进入 github 中该项目的 Settings 页面;

设置 Default Branch 为其他的分支(例如 master);

重新执行删除远程分支命令。

重命名本地分支:

git branch -m

推送本地分支:

git push origin

3.为分支打上 tag

为本地分支打上 tag

git tag -a v1.0.0 -m 'version 1.0.0'

把本地tag推送到远程:

推送本地全部的 tag

git push --tags

推送本地指定的 tag

git push origin

获取远程tag

git fetch origin tag

项目编译

配置 apk 文件输出名称

buildTypes {

release {

applicationVariants.all { variant ->

variant.outputs.each { output ->

def outputFile = output.outputFile

if (outputFile != null && outputFile.name.endsWith('.apk')) {

// 输出apk名称为appName-versionName-release.apk

def fileName = "appName-${defaultConfig.versionName}-release.apk"

output.outputFile = new File(outputFile.parent, fileName)

}

}

}

}

}

注意 Android Studio 3.0 中支持的新版本 gradle 改变 output.outputFile 为私有属性,所以上面的代码要改成:

android.applicationVariants.all { variant ->

variant.outputs.all {

outputFileName = "${variant.name}-${variant.versionName}-release.apk"

}

}

Java 8 支持

defaultConfig {

jackOptions {

enabled true

}

}

buildTypes {

compileOptions {

targetCompatibility 1.8

sourceCompatibility 1.8

}

}

注意 Android Studio 3.0 中支持的新版本 gradle 中把 jackOptions 移除。

Sources for ‘Android API 26 Platform’ not found.

这是 Android Studio 关联不上源码导致的,下载对应的 API 源码文件后,会存放在 /Users/xxxxx/Library/Android/sdk/sources/android-26 文件夹,但是有可能明明下载了源码但是 Android Studio 就是提示找不到。这是 Android Studio 配置文件未能更新导致的,可以自行修改即可:

找到以下路径,并打开文件

~/Library/Preferences/AndroidStudioXXX/options/jdk.table.xml

修改 jdk.table.xml 文件中对应 API 版本配置信息

手动配置 API 26 Sources 文件路径

8c95d76f5edf?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

保存配置文件,重新 Android Studio 即可。

项目依赖的某个模块引用了 aar 包导致的编译问题

在某个子模块 tencent-ysdk 引用了 aar 包

8c95d76f5edf?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

module.png

依赖了 aar 包的 module:tencent-ysdk 的 build.gradle

dependencies {

compile(name: 'YSDK_Android_1.3.6_841', ext: 'aar')

compile 'com.android.support:appcompat-v7:26.1.0'

compile fileTree(dir: 'libs', include: ['*.jar'])

}

应用 module:app 依赖了 tencent-ysdk模块,其 build.gradle

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')

compile 'com.android.support:appcompat-v7:26.1.0'

compile project(':comment')

compile project(':tencent-ysdk')

}

需要在 project 下的 build.gradle 中设置

allprojects {

repositories {

jcenter()

maven { url 'https://maven.google.com' }

flatDir {

// 由于Library module中引用了库的 aar,在多 module 的情况下,

// 其他的module编译会报错,所以需要在所有工程的repositories

// 下把Library module中的libs目录添加到依赖关系中

dirs project(':tencent-ysdk').file('libs')

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值