我的机器上没有互联网连接(由于某些原因),我想在它上面使用Android studio(3)而不依赖互联网。
我创建了一个非常简单(默认)的应用程序,但是出现了很多错误,我将gradle更改为本地并删除/设置了离线工作选项,但没有任何效果。
错误:
Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:26.+.
<a href="openFile:C:/MyApplication/app/build.gradle">Open File</a><br><a
href="Unable to resolve dependency for
':app@debug/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app@debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
<a href="openFile:C:/MyApplication/app/build.gradle">Open File</a><br><a
href="Unable to resolve dependency for
':app@debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for ':app@release/compileClasspath':
Could not resolve com.android.support:appcompat-v7:26.+.
<a href="openFile:C:/MyApplication/app/build.gradle">Open File</a><br><a
href="Unable to resolve dependency for
':app@release/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app@releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
<a href="openFile:C:/MyApplication/app/build.gradle">Open File</a><br><a
href="Unable to resolve dependency for
':app@releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
的build.gradle(APP):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
的build.gradle(项目):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 0 :(得分:0)
您第一次需要连接到互联网,以便可以获取所有依赖项。一旦完成,您就不再需要互联网了。
但是,如果您再次尝试构建,Android Studio(gradle)仍将尝试连接到Internet以刷新依赖项。如果你不能在线,那么你需要告诉Android Studio(即gradle)离线工作。
转到Android Studio's Preferences -> Build, Execution, Deployment -> Offline Work
启用此选项,gradle将开始脱机工作。
注意:com.android.support:appcompat-v7:26.+.
在这里不起作用。您需要提及特定工件ID而不是+
。