使用段分析的应用程序抛出java.lang.IllegalArgumentException:需要INTERNET权限

时间:2018-03-19 11:38:10

标签: robolectric robolectric-gradle-plugin

问题:我正在尝试使用robolectric为我的应用运行测试用例。我的应用程序是细分分析。它已经在我的清单文件中抛出Internet权限异常。

robolectric版本:3.7.1,targetSDKVersion:26,gradle:3.0.1     命令:./ gradlew clean testBuildDebug

system : Mac.

build.gradle file:

flavorDimensions "default"

productFlavors {
  build {
    applicationId = "com.example"
  }
}

public class DeckardApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();

    Analytics analytics;
    Analytics.Builder builder = new Analytics.Builder(this, "xyz").trackApplicationLifecycleEvents();
    builder.logLevel(Analytics.LogLevel.VERBOSE);
    analytics = builder.build();

    if (analytics != null) {
      Analytics.setSingletonInstance(analytics);
    }
  }
}

@RunWith(RobolectricTestRunner.class)
public class DeckardActivityTest {
  private DeckardActivity activity = null;

  @Before
  public void prepareActivity() {
    activity = Robolectric.setupActivity(DeckardActivity.class);
  }

  @Test
  public void testVisibility() {
    View text = activity.findViewById(R.id.text);
    TestUtility.checkViewVisible(text);
  }
}

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          android:versionCode="2"
          android:versionName="1.0.0-SNAPSHOT"
          package="com.example">
  <uses-permission android:name="android.permission.INTERNET"/>
    <application android:name=".DeckardApplication"
                 android:theme="@style/Theme.AppCompat.Light">
        <activity android:name=".activity.DeckardActivity" android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
      <activity android:name=".common.TargetActivity"/>
    </application>
</manifest>

0 个答案:

没有答案