Skip to content

adb: failed to stat app/build/outputs/apk/app-debug.apk: No such file or directory #124

Closed

Description

@matart15

Environment

"react": "^16.0.0",
"react-native": "0.51.1",
Andriod Sdk: 26.0.2

Description

**BUILD SUCCESSFUL in 2m 18s**
164 actionable tasks: 3 executed, 161 up-to-date
Running /home/rivertech/Android/Sdk/platform-tools/adb -s ZY2243ZMVC reverse tcp:8081 tcp:8081
adb server version (36) doesn't match this client (39); killing...
* daemon started successfully
Installing the app on the device (cd android && adb -s ZY2243ZMVC install app/build/outputs/apk/app-debug.apk
**adb: failed to stat app/build/outputs/apk/app-debug.apk: No such file or directory**
Command failed: /home/rivertech/Android/Sdk/platform-tools/adb -s ZY2243ZMVC install app/build/outputs/apk/app-debug.apk
**Could not install the app on the device, read the error above for details.**

Starting the app on ZY2243ZMVC (/home/rivertech/Android/Sdk/platform-tools/adb -s ZY2243ZMVC shell am start -n com.demo/com.demo.MainActivity)...
Starting: Intent { cmp=com.demo/.MainActivity }
Error type 3
Error: Activity class {com.demo/com.demo.MainActivity} does not exist.

Reproducible Demo

same issue
react/react-native#18243

android/app/build/output/apk has child directories debug and release

https://github.com/react-native-community/react-native-cli/blob/03dc0768f762970b40a99285e8334ba6da7e1728/packages/cli/src/runAndroid/runAndroid.js#L173

Activity

  1. added
    bug
    on Jan 25, 2019
  2. grabbou commented on Mar 11, 2019

    @grabbou
    Member

    CC: @sidferreira @ferrannp - do you have an idea why this could be happening (two folders inside apk?) There's some decent conversation happening in React Native repository too.

  3. sidferreira commented on Mar 11, 2019

    @sidferreira

    @grabbou AFAIK this is actually a gradle/android thing. In the past, I wanted to rename the generated files and it was a lot of work because it was forcing the folder even with me renaming the apk file.

    @matart15 have you tried to rename the generated APK by any chance?

  4. sidferreira commented on Mar 11, 2019

    @sidferreira

    @matart15 What's your gradle version?

  5. matart15 commented on Mar 12, 2019

    @matart15
    Author
    ------------------------------------------------------------
    Gradle 4.7
    ------------------------------------------------------------
    
    Build time:   2018-04-18 09:09:12 UTC
    Revision:     b9a962bf70638332300e7f810689cb2febbd4a6c
    
    Groovy:       2.4.12
    Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
    JVM:          1.8.0_111 (Oracle Corporation 25.111-b14)
    OS:           Mac OS X 10.14.1 x86_64
    
  6. matart15 commented on Mar 12, 2019

    @matart15
    Author

    for now I am using workaround

    android.applicationVariants.all { variant ->
        variant.outputs.all {
            // https://github.com/react-native-community/react-native-cli/issues/124
            outputFileName = "../app-${variant.name}.apk"
        }
     }
    
  7. grabbou commented on Mar 12, 2019

    @grabbou
    Member

    I wonder if it's possible to somehow dynamically get this apk file just like we did with flavours recently.

  8. sidferreira commented on Mar 12, 2019

    @sidferreira

    @grabbou can't we look for the newest generated APK in the folder?

  9. grabbou commented on Mar 12, 2019

    @grabbou
    Member
  10. thymikee commented on Jul 7, 2019

    @thymikee
    Member

    Is this still an issue?

  11. ldco2016 commented on Sep 26, 2019

    @ldco2016

    This may be a relevant issue for me as well. I have a script that generates apks and it generates all the flavours correctly except for INT:

    import fs from "fs-extra";
    import eachSeries from "async/eachSeries";
    import { exec } from "child_process";
    import { androidDirectory } from "../../app.json";
    import { resolveFromRoot, distDir, createLogger } from "../build";
    
    const logger = createLogger("android");
    
    const APK_PATTERN = /release\.apk$/i;
    
    function copyArtifactsToDist() {
      logger.logHeader("Copying APK to Dist", { repeatChar: "=" });
      const baseDir = `${androidDirectory}/app/build/outputs/apk`;
    
      const allFlavs = ["dev", "qa", "ua", "prod", "in"];
      const branchName = process.env.GitVersion_BranchName || "";
      const buildFlavour = branchName.startsWith("release/") ? allFlavs : ["dev"];
      const envs = {
        dev: "DEV",
        qa: "QA",
        ua: "UA",
        in: "INT",
        prod: ""
      };
    
      buildFlavour
        .map(env => {
          const apkOutputDir = resolveFromRoot(`${baseDir}/${env}/release`);
          return {
            apkOutputDir,
            env
          };
        })
        .forEach(({ apkOutputDir, env }) => {
          const src = `${apkOutputDir}/app-${env}-release.apk`;
          //prettier-ignore
          const binaryName = env === 'prod' ? 'ENGAL.apk' : `ENGAL-${envs[env]}.apk`;
          const dest = `${distDir}/${binaryName}`;
          fs.copy(src, dest, (err: Error) => {
            if (err) {
              logger.error(err);
            }
          });
        });
    }
    
    function run() {
      logger.logHeader("Starting Android Builds", { repeatChar: "#" });
      const flavours = [
        {
          endpoint: "dv",
          flavour: "Dev",
          appcenterKey: "a014b1a3-c1e6-4fa2-9cae-078ff1b510a2"
        },
        {
          endpoint: "qa",
          flavour: "Qa",
          appcenterKey: "0291d693-bd16-4fde-ada7-f6b6f2e97a59"
        },
        {
          endpoint: "ua",
          flavour: "Ua",
          appcenterKey: "0050def9-48ae-4d56-81f8-4d5242a9c639"
        },
        {
          endpoint: "prod",
          flavour: "Prod",
          appcenterKey: "0cb99e08-2092-43cb-8abe-49e580717221"
        },
        {
          endpoint: "in",
          flavour: "Int",
          appcenterKey: "f743d50f-82fa-4b23-b602-2a318b875480"
        }
      ];
    
      const versionCode = process.env.Build || 1;
      const release = process.env.GitVersion_MajorMinorPatch || "4.0.0";
      const fullAppVersion = `${release}-${versionCode}`;
    
      const devFlav = flavours.find(f => f.flavour.toLocaleLowerCase() === "dev");
    
      const branchName = process.env.GitVersion_BranchName || "";
      const buildFlavour = branchName.startsWith("release/") ? flavours : [devFlav];
    
      eachSeries(
        buildFlavour,
        (f, callback) => {
          //prettier-ignore
          logger.logHeader(
            `starting gradle assemble${f.flavour}Release with flag - versionName=${fullAppVersion} -PversionCode=${versionCode}`,
            {repeatChar: '-'}
          );
    
          const engaInfo = `ENGAGE_VERSION=${fullAppVersion}`;
          const engaEndpoint = `ENGAGE_ENDPOINT=${f.endpoint}`;
          const engaCenter = `APPCENTER_KEY=${f.appcenterKey}`;
          const engaPlatform = "APPCENTER_PLATFORM=android";
          //prettier-ignore
          const prepare = `${engaEndpoint} ${engaCenter} ${engaInfo} ${engaPlatform} npm run setup`;
          const cd = `cd ${androidDirectory}`;
          //prettier-ignore
          const releaseCmd = `./gradlew assemble${f.flavour}Release -PversionName=${fullAppVersion} -PversionCode=${versionCode} && cd ..`;
    
          exec(`${prepare} && ${cd} && ${releaseCmd}`, err => {
            if (err) {
              return callback(err);
            }
    
            logger.logHeader(`${f.flavour} Android Build Successful!`, {
              repeatChar: "#"
            });
            // logger.close();
            callback(null);
          });
        },
        error => {
          if (error) {
            logger.logHeader("Android Builds Failed!", {
              repeatChar: "#"
            });
            logger.error(error);
            logger.close();
          }
          // error below
          copyArtifactsToDist();
        }
      );
    }
    
    run();
    

    When its time for the INT flavour to generate, I get this:

    ######################## Int Android Build Successful! ########################
    ============================= Copying APK to Dist =============================
    { [Error: ENOENT: no such file or directory, stat '/Users/danale/Projects/NFIBEngage/android/app/build/outputs/apk/in/release/app-in-release.apk']
      errno: -2,
      code: 'ENOENT',
      syscall: 'stat',
      path:
       '/Users/danale/Projects/NFIBEngage/android/app/build/outputs/apk/in/release/app-in-release.apk' }
    

    instead of ENGAL-IN.apk in the dist/ directory where the others are placed. I thought it was a naming convention, but I have tweaked the naming and I continue to get this output.

  12. added this to the 4.x milestone on Mar 11, 2020
  13. dcalhoun commented on Apr 8, 2020

    @dcalhoun

    I wanted to share that this does appear still be an issue, at least for me. The failure only occurs when passing deviceId.

    Succeeds: yarn react-native run-android --variant=localGoogleDebug
    Fails: yarn react-native run-android --variant=localGoogleDebug --deviceId=<target-device-id>

    I have a few build variants configured, for both environment, platform, and debuggable (e.g. localGoogleDebug). Including deviceId in the CLI command arguments results in the following error:

    BUILD SUCCESSFUL in 2m 48s
    1042 actionable tasks: 25 executed, 1017 up-to-date
    info Connecting to the development server...
    error Failed to install the app on the device. Run CLI with --verbose flag for more details.
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    

    While no explicit error is actually logged from the CLI, from my own debugging it would appear that my build APK is not found.

    Actual APK: app/build/outputs/apk/localGoogleDebug/debug/app-local-google-debug.apk
    CLI Search: app/build/outputs/apk/localgoogledebug/app-localgoogledebug.apk

    The workaround from #124 does not appear to address my issue.

    Environment

    • React Native 0.61.5
    • CLI 3.2.0
    • macOS 10.15.4
  14. github-actions commented on Dec 1, 2022

    @github-actions

    There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplatform: androidstale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions