Android: Adding SEND_SMS permission causes gradle

2019-06-07 20:00发布

问题:

I'm starting a simple app to send an SMS at the press of a button. I'm testing this on my mobile phone since i need the network. The app build fine the first time but the button press didn't do anything since i forgot to add the permission android.permission.SEND_SMS. Once i added that then faced with following error.

Error:java.io.FileNotFoundException: C:\Users\user\AndroidStudioProjects\myApp\app\build\intermediates\res\resources-debug.ap_ (Access is denied)
 C:\Users\user\AndroidStudioProjects\myApp\app\build\intermediates\res\resources-debug.ap_ (Access is denied)

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.android.myapp">
  <uses-permission android:name="android.permission.SEND_SMS" />
  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

If I delete the uses-permission tag the app builds without a problem. But when I add it it fails. Any assistance would be greatly appreciated!

Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.test.android.myapp"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

回答1:

I figured it out! To anyone else trying to figure this out, you need both android.permission.SEND_SMS and android.permission.RECEIVE_SMS in your manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.android.myapp">
  <uses-permission android:name="android.permission.SEND_SMS" />
  <uses-permission android:name="android.permission.RECEIVE_SMS" />
  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>


回答2:

It means you don't have permission to edit or modify, Please "intermediates" folder and clean again and build. Hopefully it will work. C:\Users\user\AndroidStudioProjects\myApp\app\build\intermediates\

or check permissions something etc.

If you're just importing some jar files, you could try to remove them and add them one at a time. This will help you determine which one of them causes the error.