简体   繁体   English

AAR Android 11 添加外部库的权限

[英]Permissions on AAR Android 11 adding external library

I am developing an application that makes use of a third party SDK, this SDK comes in an example project.我正在开发一个使用第三方 SDK 的应用程序,这个 SDK 来自一个示例项目。 I only copied the contents of the libs folder to a new project, Add the library in the build.gradle and it loads without problems, since I can see it in code and use its classes without any exceptions, the problem is that it gives me a permissions error in the Log.我只将 libs 文件夹的内容复制到一个新项目中,在 build.gradle 中添加库,它加载没有问题,因为我可以在代码中看到它并使用它的类而没有任何异常,问题是它给了我日志中的权限错误。

I/DeviceAPI: UHF device = C72_6765 I/DeviceAPI:UHF 设备 = C72_6765

I/DeviceAPI: UHF_Init----------->DEVICE_C72_6765 I/DeviceAPI: UHF_Init------------>DEVICE_C72_6765

D/DeviceAPI: [mt_gpio_ioctl] platform=6765, gpio=set 165 0111000100, gpiolen=18 D/DeviceAPI:[mt_gpio_ioctl]平台=6765,gpio=set 165 0111000100,gpiolen=18

E/DeviceAPI: [mt_gpio_ioctl] open error: [13]: Permission denied E/DeviceAPI:[mt_gpio_ioctl] 打开错误:[13]:权限被拒绝

D/DeviceAPI: [mt_gpio_ioctl] platform=6765, gpio=set 21 0111000100, gpiolen=17 D/DeviceAPI:[mt_gpio_ioctl]平台=6765,gpio=set 21 0111000100,gpiolen=17

E/DeviceAPI: [mt_gpio_ioctl] open error: [13]: Permission denied W/_solutions.rfid: type=1400 audit(0.0:1956): avc: denied { read write } for name="mt_gpio" dev="sysfs" ino=35345 scontext=u:r:untrusted_app:s0:c172,c256,c512,c768 tcontext=u:object_r:mt_gpio:s0 tclass=file permissive=0 app=com.computx_solutions.rfid E/DeviceAPI: [mt_gpio_ioctl] 打开错误: [13]: Permission denied W/_solutions.rfid: type=1400 audit(0.0:1956): avc: denied { read write } for name="mt_gpio" dev="sysfs" ino=35345 scontext=u:r:untrusted_app:s0:c172,c256,c512,c768 tcontext=u:object_r:mt_gpio:s0 tclass=file permissive=0 app=com.computx_solutions.rfid

I/DeviceAPI: UHF_Init----------->DevIsOpen = 1 I/DeviceAPI: UHF_Init----------->DevIsOpen = 1

I/DeviceAPI: UHF_OpenAndConnect: uart = /dev/ttyS1 I/DeviceAPI: UHF_OpenAndConnect: uart = /dev/ttyS1

D/DeviceAPI_SerialPort: [SerialPort_Open] [13]: Permission denied D/DeviceAPI_SerialPort:[SerialPort_Open] [13]:权限被拒绝

All Permission Denied errors do not appear in the sample application.示例应用程序中不会出现所有 Permission Denied 错误。

Working App build.gradle工作应用程序 build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
}
android {
    compileSdkVersion 31
//    buildToolsVersion "30.0.3"
    defaultConfig {
        applicationId "com.android.uhftest"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        //testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                abiFilters "armeabi"//abi体系结构下的so库
            }
        }
        vectorDrawables {
            useSupportLibrary true
        }
    }

    signingConfigs {
        debug {
            File strFile = new File("/chainway.keystore")
            storeFile file(strFile)
            storePassword "123456"
            keyPassword "123456"
            keyAlias "chainway"
        }
        release {
            File strFile = new File("/chainway.keystore")
            storeFile file(strFile)
            storePassword "123456"
            keyPassword "123456"
            keyAlias "chainway"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation files('libs/DeviceAPI_ver20220323_release.aar')


    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"

}

Working manifest.xml工作清单.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.uhf"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:screenOrientation="portrait"
        android:theme="@style/CustomTheme">
        <activity
            android:name=".MainActivity"
            android:label="Main Acitivity"
            android:theme="@style/CustomTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activity.UHFMainActivity"
            android:label="@string/app_name" />
    </application>

</manifest>

NOT Working build.gradle不工作 build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.computx_solutions.rfid"
        minSdk 27
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"


    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation files('libs/DeviceAPI_ver20220323_release.aar')
}

NOT working manifest不工作清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.computx_solutions.rfid">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:requestLegacyExternalStorage="true"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.RFIDInventory"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/Theme.RFIDInventory">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

I also tried to put the same sdk in both projects and it didn't work.我还尝试在两个项目中放置相同的 sdk,但没有成功。 Is there any other file that involves permissions or configurations of the external libraries that you are not considering?是否有任何其他文件涉及您不考虑的外部库的权限或配置?

It is worth mentioning that this error only occurs with android 11 since previously I was using a device with android 8 and it did not give me permission errors, I also tried to grant full write and read permissions and it did not work, besides that I have access to the code that works and nowhere does it use the permissions request and even in android it shows that it does not have any special permissions.值得一提的是,此错误仅发生在 android 11 上,因为之前我使用的是带有 android 8 的设备并且它没有给我权限错误,我还尝试授予完整的写入和读取权限,但它不起作用,除此之外我可以访问有效的代码,并且它在任何地方都没有使用权限请求,即使在 android 中它也表明它没有任何特殊权限。

I got it working adding the signing configs.我让它添加签名配置。 Sometimes it still doesn't work and it stops at init() err UHFOpenAndConnect result:-1 .有时它仍然不起作用,它在init() err UHFOpenAndConnect result:-1处停止。 I don't know what they did in the new APIs.我不知道他们在新 API 中做了什么。
I copied the files chainway.keystore and in build.gradle I added:我复制了文件 chainway.keystore 并在build.gradle中添加了:

signingConfigs {
    debug {
        File strFile = new File("/chainway.keystore")
        storeFile file(strFile)
        storePassword "123456"
        keyPassword "123456"
        keyAlias "chainway"
    }
    release {
        File strFile = new File("/chainway.keystore")
        storeFile file(strFile)
        storePassword "123456"
        keyPassword "123456"
        keyAlias "chainway"
    }
}

buildTypes {
    release {
        minifyEnabled false
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

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

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