title: Hosting an executable within a Flutter application
body: <p>I have a basic flutter project running on android where when the application starts, I write an executable bundled in my assets.</p>
  <pre><code>  static String appInternalPath = '/data/data/com.maksimdan.face_merger';
  
    void writeExecutable() async {
      var executablePath = join(appInternalPath, 'main');
  
      if (await File(executablePath).exists()) {
        File(executablePath).delete();
        print('deleted old executable');
      } else {
        print('not executable exists');
      }
  
      ByteData data = await rootBundle.load('lib/py/dist/main');
      List&lt;int&gt; bytes =
          data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
      await File(executablePath).writeAsBytes(bytes);
      print('wrote new executable');
    }
  </code></pre>
  <p>Sometime later in my code I try to run it.</p>
  <pre><code>  void invokeExecutable() async {
      String executablePath = join(appInternalPath, 'main');
      Process.run('chmod', ['u+x', executablePath]).then((ProcessResult results) {
        Process.run(executablePath, []).then((ProcessResult results) {
          print(results.stdout);
        });
      });
    }
  </code></pre>
  <p>But obtain a permission denied error.</p>
  <pre><code>E/flutter (31825): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: ProcessException: Permission denied
  E/flutter (31825):   Command: /data/data/com.maksimdan.flutter_general/main 
  E/flutter (31825): #0      _ProcessImpl._start (dart:io-patch/process_patch.dart:390:33)
  E/flutter (31825): #1      Process.start (dart:io-patch/process_patch.dart:36:20)
  E/flutter (31825): #2      _runNonInteractiveProcess (dart:io-patch/process_patch.dart:565:18)
  E/flutter (31825): #3      Process.run (dart:io-patch/process_patch.dart:47:12)
  E/flutter (31825): #4      _MyHomePageState.invokeExecutable.&lt;anonymous closure&gt; (package:flutter_general/main.dart:51:15)
  E/flutter (31825): #5      _rootRunUnary (dart:async/zone.dart:1362:47)
  E/flutter (31825): #6      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
  E/flutter (31825): &lt;asynchronous suspension&gt;
  </code></pre>
  <p>I've also tried:</p>
  <pre><code>      Process.run('/system/bin/chmod', ['744', path]).then((ProcessResult results) {
          print('shell1 complete');
          Process.run(path, []).then((ProcessResult results) {
            print('shell2 complete');
            print(results.stdout);
          });
        });
  </code></pre>
  <p>My executable:</p>
  <pre class="lang-cpp prettyprint-override"><code>// 'Hello World!' program 
   
  #include &lt;iostream&gt;
   
  int main()
  {
    std::cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; std::endl;
    return 0;
  }
  </code></pre>
  <pre><code>&gt;&gt; g++ main.cc -o main
  </code></pre>
  <p>Is there a way to run your own executables in flutter with the proper permissions? On native android, there is an option to <code>file.setExecutable(true);</code> using this strategy. (<a href="https://stackoverflow.com/questions/5583487/hosting-an-executable-within-android-application">Hosting an executable within Android application</a>)</p>
  <p>Or will I have to experiment with method channels?</p>
  <hr />
  <p>pubspec.yml</p>
  <pre><code>name: face_merger
  description: A new Flutter project.
  
  version: 1.0.0+1
  
  environment:
    sdk: &quot;&gt;=2.1.0 &lt;3.0.0&quot;
  
  dependencies:
    flutter:
      sdk: flutter
  
    sqflite: ^1.3.0+2
    process_run: ^0.10.10+1
    cupertino_icons: ^0.1.3
  
  dev_dependencies:
    flutter_test:
      sdk: flutter
  
  
  flutter:
    uses-material-design: true
    assets:
      - lib/py/dist/main
  </code></pre>
  <p>I also verified that the file was written to the internal memory of on the device that I expected it to be written to using android studio's device explore.</p>
  <p><a href="https://i.stack.imgur.com/oMlLc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oMlLc.png" alt="screenshot of executable within the android simulator" /></a></p>