【问题标题】:Error - Attribute 'android:testOnly' not found错误 - 未找到属性“android:testOnly”
【发布时间】:2018-02-20 19:34:36
【问题描述】:

我正在尝试在 DropBox Android SDK 中运行示例“DBRoulette”:

https://www.dropbox.com/developers-v1/core/sdks/android

当我在 Android Studio (Build --> Rebuild Project) 中构建项目时,我没有收到任何错误,但是当我尝试在我的设备上运行代码时(来自 Android Studio)我收到错误:

“找不到属性‘android:testOnly’”

我可以看到这条线:

android:testOnly="true"

在“AndroidManifest.xml”文件中,但据我了解,我无法编辑此文件并将其更改为testOnly=false

有什么问题?为什么会出现此错误?

(如果很重要,我使用的是 Gradle-4.5.1)


这是我收到的完整构建消息:

Information:Gradle tasks [:app:assembleDebug]
D:\AndroidProjects\DropboxSDK-1.6.3\DBRouletteTest\app\build\intermediates\manifests\instant-run\debug\AndroidManifest.xml
Error:(12) error: attribute 'android:testOnly' not found.
Error:(12) attribute 'android:testOnly' not found.
Error:failed processing manifest.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Information:BUILD FAILED in 0s
Information:6 errors
Information:0 warnings
Information:See complete output in console

这里是 AndroidManifest.xml:

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

    <uses-sdk android:minSdkVersion="3" />

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

    <application
        android:debuggable="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:testOnly="true" >
        <activity
            android:name="com.dropbox.android.sample.DBRoulette"
            android:configChanges="orientation|keyboard"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.dropbox.client2.android.AuthActivity"
            android:configChanges="orientation|keyboard"
            android:launchMode="singleTask" >
            <intent-filter>

                <!-- Change this to be db- followed by your app key -->
                <data android:scheme="db-CHANGE_ME" />

                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <provider
            android:name="com.android.tools.ir.server.InstantRunContentProvider"
            android:authorities="com.dropbox.android.sample.com.android.tools.ir.server.InstantRunContentProvider"
            android:multiprocess="true" />
    </application>

</manifest>

【问题讨论】:

标签: android android-studio sdk runtime dropbox


【解决方案1】:

build.gradle 中将 compileSdkVersion 更改为更高。我将 compileSdkVersion 更改为 28,它可以工作。

【讨论】:

    【解决方案2】:

    我想,也许吧。最后,我通过执行以下操作成功启动了该应用程序:

    复制我的AndroidManifest.xml 并输入您的密钥。 在 DBRoulette.class 中添加您的密钥和秘密。 在build.gradle(Module:app) 文件中,将最小 sdk 从 3 更改为 4。

    这对我有用,因为 android:testOnly 功能在 API 3 中不可用(根据 Android Studio 的警告) 如果我告诉您的内容有效,则说明 API 3 产生了问题,并通过将其标记为正确来结束问题,否则请解释进一步的问题。

    我的清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dropbox.android.sample"
    android:versionCode="1"
    android:versionName="1.0">
    
    <uses-sdk android:minSdkVersion="3" />
    
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission     android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    <application android:icon="@drawable/icon"
        android:label="@string/app_name">
        <activity
            android:name=".DBRoulette"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboard">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <activity
            android:name="com.dropbox.client2.android.AuthActivity"
            android:launchMode="singleTask"
            android:configChanges="orientation|keyboard">
            <intent-filter>
                <!-- Change this to be db- followed by your app key -->
                <data android:scheme="db-YOUR_TOKEN" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    
    </application>
    </manifest>
    

    【讨论】:

    • 好的,我按照你的要求添加了“AndroidManifest.xml”文件,有帮助吗?
    • 我试过你的“AndroidManifest.xml”文件(我改成我的APP_KEY),但还是一样的错误。
    • 我尝试手动重新添加它,我尝试删除此行,我还尝试将值更改为“false”。在所有情况下,Rebuid 项目都可以,没有任何错误,但是当我尝试运行它时,我得到了错误,并且 testOnly=true 再次出现并进行了一些修改。
    • 您使用的是 Api v1 还是最新版本?
    猜你喜欢
    • 2020-03-17
    • 2020-07-06
    • 2022-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-16
    相关资源
    最近更新 更多