gpt4 book ai didi

android - 无法在 Android studio 中运行 hello world

转载 作者:行者123 更新时间:2023-11-30 00:49:28 25 4
gpt4 key购买 nike

我安装了一个 Android Studio 并创建了一个新的 Hello World 应用程序。我尝试使用我设置的模拟器运行,但 gradle sync 给我错误,如下所示。我是 android 开发的新手。任何帮助都会很棒。

我的 build.gradle 是:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
mavenCentral()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

我的 build.gradle 用于(模块应用)

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.rohit_mourya.helloworld"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
androidTestCompile 'junit:junit:4.12'
compile 'javax.inject:javax.inject:1'
compile 'javax.annotation:jsr250-api:1.0-20050927.133100'
}

当我尝试运行我的应用程序时,出现以下错误:

C:\Users\rohit_mourya\AndroidStudioProjects\HelloWorld\app\build.gradle
Error:Error:line (27)Failed to resolve: junit:junit:4.12
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:line (28)Failed to resolve: javax.inject:javax.inject:1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:Failed to resolve: javax.annotation:javax.annotation-api:1.2
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:Failed to resolve: com.google.code.findbugs:jsr305:2.0.1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:Failed to resolve: org.hamcrest:hamcrest-library:1.3
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:Failed to resolve: org.hamcrest:hamcrest-integration:1.3
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:line (29)Failed to resolve: javax.annotation:jsr250-api:1.0-20050927.133100
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>
Error:Error:Failed to resolve: com.squareup:javawriter:2.1.1
<a href="openFile:C:/Users/rohit_mourya/AndroidStudioProjects/HelloWorld/app/build.gradle">Open File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>

尽管我已经在项目的模块设置中配置了这些依赖项。提前谢谢你

最佳答案

在你的 build.gradle 中使用它

    apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
sourceSets.main {

jniLibs.srcDir 'src/main/libs'
//hide the ‘jni’ folder so that the automatic gradle build doesn’t try to run

//it’s own ndk-build process

jni.srcDirs = [];
}
defaultConfig {
applicationId 'com.example.rohit_mourya.helloworld'
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

productFlavors {
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
}

关于android - 无法在 Android studio 中运行 hello world,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41299550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com