简体   繁体   English

Android Studio Gradle无法同步

[英]Android Studio Gradle not Syncing

I'm very new to Android Studio and I'm basically trying to open an existing project that I had downloaded and compile/run it. 我是Android Studio的新手,我基本上是想打开一个我下载并编译/运行它的现有项目。 I am getting the following error when Gradle attempts to sync... 当Gradle尝试同步时出现以下错误...

Error:Cannot read packageName from /Users/Amanda/Desktop/MyProject/src/main/AndroidManifest.xml

I have researched online and have tried several solutions, none of which have fixed my problem :/ I have also tried to "invalidate caches and restart" but it did not work either... 我在网上进行了研究,并尝试了几种解决方案,但都没有解决我的问题://我也尝试过“使缓存无效并重新启动”,但是它也不起作用。

This is my Manifest: 这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="me.amanda.myproject.app">
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="My Project">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity
            android:name=".resourceListing"
            android:label="My App Listing">
        </activity>
        <activity
            android:name=".ListApps"
            android:label="@string/title_activity_list_apps">
        </activity>
    </application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>

My build.gradle: 我的build.gradle:

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

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

allprojects {
    repositories {
        mavenCentral()
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

}
dependencies {
}

some times clean cant delete some of build folder files. 有时clean无法删除某些构建文件夹文件。

try these steps : 请尝试以下步骤:

1- make a copy of your manifest file and delete your manifest file from project. 1-复制清单文件,然后从项目中删除清单文件。

2- delete your app/build folder. 2-删除您的app/build文件夹。

3-then clean your project 3-然后清理您的项目

4- add the manifest file again to src/main directory 4-再次将清单文件添加到src/main目录

5- clean the project again 5-再次清理项目

6- rebuild the project 6-重建项目

Set your packageName as applicationId in your build.gradle file. build.gradle文件build.gradle packageName设置为applicationId

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "me.amanda.myproject.app"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.1"
}

Now, when you build apk your packageName will replace with defaultConfig > applicationId 现在,当您构建apk时,您的packageName将替换为defaultConfig> applicationId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM