GVKun编程网logo

react-native run-android命令失败,但是gradlew installDebug工作(react-native-win32.dll)

14

如果您想了解react-nativerun-android命令失败,但是gradlewinstallDebug工作的相关知识,那么本文是一篇不可错过的文章,我们将对react-native-win32

如果您想了解react-native run-android命令失败,但是gradlew installDebug工作的相关知识,那么本文是一篇不可错过的文章,我们将对react-native-win32.dll进行全面详尽的解释,并且为您提供关于Android gradle’installDebug’任务在更新后停止工作、Android Native Activity 的 gradle 配置、Android Studio 3.0 – 对于externalNativeBuild,Gradle Sync失败、android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中的有价值的信息。

本文目录一览:

react-native run-android命令失败,但是gradlew installDebug工作(react-native-win32.dll)

react-native run-android命令失败,但是gradlew installDebug工作(react-native-win32.dll)

我在OSX上使用react-native 0.43.3.
我试图在 Android上运行应用程序并获取消息
react-native run-android

Scanning 568 folders for symlinks in /Users/ruci.k/project/mayacrew/supermembers/supermembers/node_modules (5ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Could not install the app on the device,read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

./gradlew installDebug给了我一些错误并修复了一切.
最后构建成功,应用程序正在Android设备上运行.

但react-native run-android命令仍无效.
只有./gradlew installDebug命令工作.

有什么可以检查使用react-native run-android命令吗?

我无法理解它是怎么发生的.

尝试删除android,ios文件夹,然后做反应原生升级,然后再次尝试react-native run-android之后,如果你得到一个错误,如

SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

然后在该文件夹中创建一个名为local.properties的文件

android

并插入以下行sdk.dir = / path / to / Android / Sdk之后一切都应该没问题

Android gradle’installDebug’任务在更新后停止工作

Android gradle’installDebug’任务在更新后停止工作

更新gradle插件后,任务installDevDebug停止工作
2.1.3至2.3.3

./gradlew installDevDebug
...
Unable to install 
/Users/user/Android/MyApp/app/build/outputs/apk/App-1.34.0-dev-
debug-unaligned.apk
com.android.ddmlib.InstallException: Failed to install all
    at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:96)
    at com.android.ddmlib.Device.installPackages(Device.java:904)
    at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:136)
    at com.android.build.gradle.internal.tasks.InstallVariantTask.install(InstallVariantTask.java:134)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)

的build.gradle

...
buildscript {
    ext.gradle_plugin_version = ''2.3.3''
}

android {
    compileSdkVersion 25
    buildToolsversion "25.0.3"

...
    productFlavors {
        prod {
        }
        dev {
            minSdkVersion 21
            multiDexEnabled true
        }
    }
}

有人可以解释gradle插件中发生了什么变化,以及如何解决这个问题?
也许问题在于构建口味?
谢谢.

解决方法

我发现我必须在将Intellij升级到2017.2的同时指定这个maven存储库(这就是强迫gradle插件升级到我身上的原因).

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Android Native Activity 的 gradle 配置

Android Native Activity 的 gradle 配置

实例项目的module结构

image_thumb

app module 的 manifests,其中android:value=”native-activity”与nativeactivity的build.gradle中的moduleName对应

<?xml version="1.0" encoding="utf-8"?><!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.native_activity"
    android:versionCode="1"
    android:versionName="1.0">
    <!-- This .apk has no Java code itself, so set hasCode to false. -->
    <application
        android:allowBackup="false"
        android:fullBackupContent="false"
        android:hasCode="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">
        <!-- Our activity is the built-in NativeActivity framework class.
             This will take care of integrating with our NDK code. -->
        <activity
            android:name="android.app.NativeActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name">
            <!-- Tell NativeActivity the name of or .so -->
            <meta-data
                android:name="android.app.lib_name"
                android:value="native-activity" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest><!-- END_INCLUDE(manifest) -->

native module的manifests

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.foohao.nativeactivity">
    <application/>
</manifest>

项目的build.gradle

// Top-level build file where you can add
// configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath ''com.android.tools.build:gradle-experimental:0.7.0''
    }
}
allprojects {
    repositories {
        jcenter()
    }
}

app module的 build.gradle

apply plugin: ''com.android.model.application''
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = ''23.0.3''
        defaultConfig {
            applicationId = ''com.example.native_activity''
            minSdkVersion.apiLevel    = 18
            targetSdkVersion.apiLevel = 23
        }
        ndk {
            platformVersion = 18
            moduleName =''native-activity''
            toolchain = ''gcc''
            stl = ''gnustl_static''
            cppFlags.add(''-std=c++11'')
            ldLibs.addAll([''log'', ''android'', ''EGL'', ''GLESv1_CM''])
        }
        sources {
            main {
                jni {
                    dependencies {
                        project '':nativeactivity'' linkage ''static''
                    }
                }
            }
        }
        buildTypes {
            release {
                minifyEnabled = false
                proguardFiles.add(file(''proguard-rules.txt''))
            }
        }
    }
}

nativeactivity module的 build.gradle

apply plugin: ''com.android.model.library''
def ndkDir = System.getenv("ANDROID_NDK_HOME")
def propertiesFile = project.rootProject.file(''local.properties'')
if (propertiesFile.exists()) {
    Properties properties = new Properties()
    properties.load(propertiesFile.newDataInputStream())
    ndkDir = properties.getProperty(''ndk.dir'')
}
model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.3"
        defaultConfig.with {
            minSdkVersion.apiLevel = 18
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "0.0.1"
        }
        ndk {
            moduleName = ''native-activity''
            toolchain = ''gcc''
            ldLibs.addAll([''log'', ''android''])
            ldFlags.add("-c")
        }
        sources {
            main {
                jni {
                    source {
                        srcDir "${ndkDir}/sources/android/native_app_glue"
                    }
                    exportedHeaders {
                        srcDir "${ndkDir}/sources/android/native_app_glue"
                    }
                }
            }
        }
    }
}

Android Studio 3.0 – 对于externalNativeBuild,Gradle Sync失败

Android Studio 3.0 – 对于externalNativeBuild,Gradle Sync失败

当我迁移到 Android studio 3.0时,我得到以下回溯
* What went wrong:
Could not determine the dependencies of task ':celltower:compileExternalNativeBuildJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':celltower:externalNativeBuildCompileClasspath'.
   > Could not resolve project :commonandroidutils.
     required by:
         project :celltower
      > Unable to find a matching configuration of project :commonandroidutils:
          - Configuration 'debugApiElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
   > Could not resolve project :wimtutils.
     required by:
         project :celltower
      > Unable to find a matching configuration of project :wimtutils:
          - Configuration 'debugApiElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'debugRuntimeElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'debug'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'debug' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.
          - Configuration 'releaseApiElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found compatible value 'java-api'.
          - Configuration 'releaseRuntimeElements':
              - required com.android.build.api.attributes.BuildTypeAttr 'externalNativeBuild' and found incompatible value 'release'.
              - required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
              - Found com.android.build.gradle.internal.dependency.VariantAttr 'release' but wasn't required.
              - required org.gradle.api.attributes.Usage 'java-api' and found incompatible value 'java-runtime'.

我的build.gradle就在这里.

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsversion "26.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            ndkBuild {
            }
        }

        ndk {
//            abiFilters   "armeabi-v7a","x86"
            abiFilters "armeabi-v7a"
            moduleName "HelloJNI"
            //ldLibs.addAll(["android","log"])
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled false

            ndk {
                abiFilters   "armeabi-v7a","x86"
                moduleName "HelloJNI"
            }
        }
        externalNativeBuild {
            ndkBuild {
                path "src/main/jni/Android.mk"
            }
        }
    }

    buildTypeMatching 'debug','release'

    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

ext {
    retrofitVersion = '2.1.0'
    rxJavaVersion = '1.2.1'
    rxAndroidVersion = '1.2.1'
    okHttpVersion = '3.4.1'
    playServicesversion = '9.8.0'
    fireBaseVersion = '9.8.0'
    daggerVersion = '2.7'
    appCompatV7Version = '26.0.1'
}

dependencies {
    implementation filetree(dir: 'libs',include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2',{
        exclude group: 'com.android.support',module: 'support-annotations'
    })
    implementation "com.android.support:support-annotations:$appCompatV7Version"
    implementation 'com.google.code.gson:gson:2.7'
    testImplementation 'junit:junit:4.12'
    implementation 'com.squareup.retrofit:retrofit:1.9.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
    implementation project(':commonandroidutils')
    implementation project(':wimtutils')
}

任何帮助深表感谢!

解决方法

我移出了buildTypes之外的externalNativeBuild并将它放在android下.它开始工作了.
android {
....
...
   buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),"x86"
                moduleName "HelloJNI"
            }
        }
    }

    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"
        }
    }

    buildTypeMatching 'debug','release'
...
....
} // end of android

android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中

android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中

如果我对应用程序进行后台处理并在一段时间后恢复它,则会收到以下异常.
如果我改变方向或背景并立即恢复应用程序(在两种情况下都执行onSaveInstanceState和onCreate),那么savedInstanceState Bundle包含正确的ArrayList,一切正常.

02-05 14:42:06.254 E/AndroidRuntime(24355):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.savant.donordetailsviewpagertitle/com.savant.donordetailsviewpagertitle.activities.DonorDetailsContainerFragmentActivity}:
java.lang.NullPointerException: expected receiver of type
com.savant.donordetailsviewpagertitle.activities.DonorDetailsContainerFragmentActivity$RunningLoadersList,
but got null

    private class RunningLoadersList extends ArrayList<RunningLoader> implements
        Parcelable {

    private static final long   serialVersionUID    = 663585476779879096L;

    public RunningLoadersList() {
    }

    @SuppressWarnings("unused")
    public RunningLoadersList(Parcel in) {
        this();
        readFromParcel(in);
    }

    private void readFromParcel(Parcel in) {

        this.clear();

        // First we have to read the list size
        int size = in.readInt();

        for (int i = 0; i < size; i++) {
            RunningLoader r = new RunningLoader(in.readInt(),
                    in.readBundle());
            this.add(r);
        }
    }

    public int describeContents() {
        return 0;
    }

    public final Parcelable.Creator<RunningLoadersList> CREATOR = new Parcelable.Creator<RunningLoadersList>() {
                                                                    public RunningLoadersList createFromParcel(Parcel in) {
                                                                        return new RunningLoadersList(in);
                                                                    }

                                                                    public RunningLoadersList[] newArray(int size) {
                                                                        return new RunningLoadersList[size];
                                                                    }
                                                                };

    public void writetoParcel(Parcel dest, int flags) {
        int size = this.size();

        // We have to write the list size, we need him recreating the list
        dest.writeInt(size);

        for (int i = 0; i < size; i++) {
            RunningLoader r = this.get(i);

            dest.writeInt(r.id);
            dest.writeBundle(r.args);
        }
    }
}

static final class RunningLoader {
    private final int       id;
    private final Bundle    args;

    RunningLoader(int _id, Bundle _args) {
        id = _id;
        args = _args;
    }
}



    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // This has to be called before setContentView and you must use the
    // class in android.support.v4.view and NOT android.view
    requestwindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.main);

    Log.d(LOG_TAG, "onCreate");

    mAdapter = new ViewPagerTitleAdapter(getSupportFragmentManager());

    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.tabindicator);
    indicator.setViewPager(mPager);

    // first check if we already have a running loader
    if ((savedInstanceState != null)
            && savedInstanceState.containsKey("RUNNING_LOADERS")) {
        mRunningLoaders = savedInstanceState.getParcelable("RUNNING_LOADERS");
    }

    if (mRunningLoaders == null) {
        mRunningLoaders = new RunningLoadersList();
    }

    if (mRunningLoaders != null) {
        for (int i = 0; i < mRunningLoaders.size(); i++) {
            StartLoader(mRunningLoaders.get(i).id,
                    mRunningLoaders.get(i).args);
        }
    }

    if (getSupportLoaderManager().hasRunningLoaders()) {
        setProgressBarIndeterminateVisibility(Boolean.TRUE);
    } else {
        setProgressBarIndeterminateVisibility(Boolean.FALSE);
    }
}


    @Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelable("RUNNING_LOADERS", mRunningLoaders);

    Log.d(LOG_TAG, "onSaveInstanceState");
}

解决方法:

Parcelable.Creator< RunningLoadersList>()必须是这样的静态

public static final Parcelable.Creator<RunningLoadersList> CREATOR = 
new Parcelable.Creator<RunningLoadersList>() {
...
...
.
}

今天的关于react-native run-android命令失败,但是gradlew installDebug工作react-native-win32.dll的分享已经结束,谢谢您的关注,如果想了解更多关于Android gradle’installDebug’任务在更新后停止工作、Android Native Activity 的 gradle 配置、Android Studio 3.0 – 对于externalNativeBuild,Gradle Sync失败、android – FragmentActivity NullPointer在onCreate savedInstanceState Bundle中的相关知识,请在本站进行查询。

本文标签: