We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
kivy/examples/android/takepicture/ fails on Android
Example cloned form GIT build with:
buildozer android debug
deployed to Android 4.4.4 crashes, from adb logcat output teh following lines seem to be relevant:

I/python  (25790):  /data/data/org.test.takepicture/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom

I/python  (25790):  Traceback (most recent call last):
I/python  (25790):    File "/home/jb/python/mread/.buildozer/android/app/main.py", line 32, in <module>
I/python  (25790):  ImportError: No module named PIL
I/python  (25790): Python for android ended.

Second line indicates problem with image library, unfortunately I have no clue how to fix it.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/android/takepicture/main.py`
Content:
```
1 '''
2 Take picture
3 ============
4 
5 .. author:: Mathieu Virbel <mat@kivy.org>
6 
7 Little example to demonstrate how to start an Intent, and get the result.
8 When you use the Android.startActivityForResult(), the result will be dispatched
9 into onActivityResult. You can catch the event with the android.activity API
10 from python-for-android project.
11 
12 If you want to compile it, don't forget to add the CAMERA permission::
13 
14     ./build.py --name 'TakePicture' --package org.test.takepicture \
15             --permission CAMERA --version 1 \
16             --private ~/code/kivy/examples/android/takepicture \
17             debug installd
18 
19 '''
20 
21 __version__ = '0.1'
22 
23 from kivy.app import App
24 from os.path import exists
25 from jnius import autoclass, cast
26 from android import activity
27 from functools import partial
28 from kivy.clock import Clock
29 from kivy.uix.scatter import Scatter
30 from kivy.properties import StringProperty
31 
32 from PIL import Image
33 
34 Intent = autoclass('android.content.Intent')
35 PythonActivity = autoclass('org.renpy.android.PythonActivity')
36 MediaStore = autoclass('android.provider.MediaStore')
37 Uri = autoclass('android.net.Uri')
38 Environment = autoclass('android.os.Environment')
39 
40 
41 class Picture(Scatter):
42     source = StringProperty(None)
43 
44 
45 class TakePictureApp(App):
46     def build(self):
47         self.index = 0
48         activity.bind(on_activity_result=self.on_activity_result)
49 
50     def get_filename(self):
51         while True:
52             self.index += 1
53             fn = (Environment.getExternalStorageDirectory().getPath() +
54                   '/takepicture{}.jpg'.format(self.index))
55             if not exists(fn):
56                 return fn
57 
58     def take_picture(self):
59         intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
60         self.last_fn = self.get_filename()
61         self.uri = Uri.parse('file://' + self.last_fn)
62         self.uri = cast('android.os.Parcelable', self.uri)
63         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
64         PythonActivity.mActivity.startActivityForResult(intent, 0x123)
65 
66     def on_activity_result(self, requestCode, resultCode, intent):
67         if requestCode == 0x123:
68             Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)
69 
70     def add_picture(self, fn, *args):
71         im = Image.open(fn)
72         width, height = im.size
73         im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)
74         im.save(fn, quality=95)
75         self.root.add_widget(Picture(source=fn, center=self.root.center))
76 
77     def on_pause(self):
78         return True
79 
80 TakePictureApp().run()
81
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/android/takepicture/main.py b/examples/android/takepicture/main.py
--- a/examples/android/takepicture/main.py
+++ b/examples/android/takepicture/main.py
@@ -23,7 +23,7 @@
 from kivy.app import App
 from os.path import exists
 from jnius import autoclass, cast
-from android import activity
+from android import activity, mActivity
 from functools import partial
 from kivy.clock import Clock
 from kivy.uix.scatter import Scatter
@@ -32,7 +32,6 @@
 from PIL import Image
 
 Intent = autoclass('android.content.Intent')
-PythonActivity = autoclass('org.renpy.android.PythonActivity')
 MediaStore = autoclass('android.provider.MediaStore')
 Uri = autoclass('android.net.Uri')
 Environment = autoclass('android.os.Environment')
@@ -61,7 +60,7 @@
         self.uri = Uri.parse('file://' + self.last_fn)
         self.uri = cast('android.os.Parcelable', self.uri)
         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
-        PythonActivity.mActivity.startActivityForResult(intent, 0x123)
+        mActivity.startActivityForResult(intent, 0x123)
 
     def on_activity_result(self, requestCode, resultCode, intent):
         if requestCode == 0x123:

{"golden_diff": "diff --git a/examples/android/takepicture/main.py b/examples/android/takepicture/main.py\n--- a/examples/android/takepicture/main.py\n+++ b/examples/android/takepicture/main.py\n@@ -23,7 +23,7 @@\n from kivy.app import App\n from os.path import exists\n from jnius import autoclass, cast\n-from android import activity\n+from android import activity, mActivity\n from functools import partial\n from kivy.clock import Clock\n from kivy.uix.scatter import Scatter\n@@ -32,7 +32,6 @@\n from PIL import Image\n \n Intent = autoclass('android.content.Intent')\n-PythonActivity = autoclass('org.renpy.android.PythonActivity')\n MediaStore = autoclass('android.provider.MediaStore')\n Uri = autoclass('android.net.Uri')\n Environment = autoclass('android.os.Environment')\n@@ -61,7 +60,7 @@\n         self.uri = Uri.parse('file://' + self.last_fn)\n         self.uri = cast('android.os.Parcelable', self.uri)\n         intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)\n-        PythonActivity.mActivity.startActivityForResult(intent, 0x123)\n+        mActivity.startActivityForResult(intent, 0x123)\n \n     def on_activity_result(self, requestCode, resultCode, intent):\n         if requestCode == 0x123:\n", "issue": "kivy/examples/android/takepicture/ fails on Android\nExample cloned form GIT build with:\nbuildozer android debug\ndeployed to Android 4.4.4 crashes, from adb logcat output teh following lines seem to be relevant:\n\nI/python  (25790):  /data/data/org.test.takepicture/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom\n\nI/python  (25790):  Traceback (most recent call last):\nI/python  (25790):    File \"/home/jb/python/mread/.buildozer/android/app/main.py\", line 32, in <module>\nI/python  (25790):  ImportError: No module named PIL\nI/python  (25790): Python for android ended.\n\nSecond line indicates problem with image library, unfortunately I have no clue how to fix it.\n\n", "before_files": [{"content": "'''\nTake picture\n============\n\n.. author:: Mathieu Virbel <mat@kivy.org>\n\nLittle example to demonstrate how to start an Intent, and get the result.\nWhen you use the Android.startActivityForResult(), the result will be dispatched\ninto onActivityResult. You can catch the event with the android.activity API\nfrom python-for-android project.\n\nIf you want to compile it, don't forget to add the CAMERA permission::\n\n    ./build.py --name 'TakePicture' --package org.test.takepicture \\\n            --permission CAMERA --version 1 \\\n            --private ~/code/kivy/examples/android/takepicture \\\n            debug installd\n\n'''\n\n__version__ = '0.1'\n\nfrom kivy.app import App\nfrom os.path import exists\nfrom jnius import autoclass, cast\nfrom android import activity\nfrom functools import partial\nfrom kivy.clock import Clock\nfrom kivy.uix.scatter import Scatter\nfrom kivy.properties import StringProperty\n\nfrom PIL import Image\n\nIntent = autoclass('android.content.Intent')\nPythonActivity = autoclass('org.renpy.android.PythonActivity')\nMediaStore = autoclass('android.provider.MediaStore')\nUri = autoclass('android.net.Uri')\nEnvironment = autoclass('android.os.Environment')\n\n\nclass Picture(Scatter):\n    source = StringProperty(None)\n\n\nclass TakePictureApp(App):\n    def build(self):\n        self.index = 0\n        activity.bind(on_activity_result=self.on_activity_result)\n\n    def get_filename(self):\n        while True:\n            self.index += 1\n            fn = (Environment.getExternalStorageDirectory().getPath() +\n                  '/takepicture{}.jpg'.format(self.index))\n            if not exists(fn):\n                return fn\n\n    def take_picture(self):\n        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)\n        self.last_fn = self.get_filename()\n        self.uri = Uri.parse('file://' + self.last_fn)\n        self.uri = cast('android.os.Parcelable', self.uri)\n        intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)\n        PythonActivity.mActivity.startActivityForResult(intent, 0x123)\n\n    def on_activity_result(self, requestCode, resultCode, intent):\n        if requestCode == 0x123:\n            Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)\n\n    def add_picture(self, fn, *args):\n        im = Image.open(fn)\n        width, height = im.size\n        im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)\n        im.save(fn, quality=95)\n        self.root.add_widget(Picture(source=fn, center=self.root.center))\n\n    def on_pause(self):\n        return True\n\nTakePictureApp().run()\n", "path": "examples/android/takepicture/main.py"}], "after_files": [{"content": "'''\nTake picture\n============\n\n.. author:: Mathieu Virbel <mat@kivy.org>\n\nLittle example to demonstrate how to start an Intent, and get the result.\nWhen you use the Android.startActivityForResult(), the result will be dispatched\ninto onActivityResult. You can catch the event with the android.activity API\nfrom python-for-android project.\n\nIf you want to compile it, don't forget to add the CAMERA permission::\n\n    ./build.py --name 'TakePicture' --package org.test.takepicture \\\n            --permission CAMERA --version 1 \\\n            --private ~/code/kivy/examples/android/takepicture \\\n            debug installd\n\n'''\n\n__version__ = '0.1'\n\nfrom kivy.app import App\nfrom os.path import exists\nfrom jnius import autoclass, cast\nfrom android import activity, mActivity\nfrom functools import partial\nfrom kivy.clock import Clock\nfrom kivy.uix.scatter import Scatter\nfrom kivy.properties import StringProperty\n\nfrom PIL import Image\n\nIntent = autoclass('android.content.Intent')\nMediaStore = autoclass('android.provider.MediaStore')\nUri = autoclass('android.net.Uri')\nEnvironment = autoclass('android.os.Environment')\n\n\nclass Picture(Scatter):\n    source = StringProperty(None)\n\n\nclass TakePictureApp(App):\n    def build(self):\n        self.index = 0\n        activity.bind(on_activity_result=self.on_activity_result)\n\n    def get_filename(self):\n        while True:\n            self.index += 1\n            fn = (Environment.getExternalStorageDirectory().getPath() +\n                  '/takepicture{}.jpg'.format(self.index))\n            if not exists(fn):\n                return fn\n\n    def take_picture(self):\n        intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)\n        self.last_fn = self.get_filename()\n        self.uri = Uri.parse('file://' + self.last_fn)\n        self.uri = cast('android.os.Parcelable', self.uri)\n        intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)\n        mActivity.startActivityForResult(intent, 0x123)\n\n    def on_activity_result(self, requestCode, resultCode, intent):\n        if requestCode == 0x123:\n            Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)\n\n    def add_picture(self, fn, *args):\n        im = Image.open(fn)\n        width, height = im.size\n        im.thumbnail((width / 4, height / 4), Image.ANTIALIAS)\n        im.save(fn, quality=95)\n        self.root.add_widget(Picture(source=fn, center=self.root.center))\n\n    def on_pause(self):\n        return True\n\nTakePictureApp().run()\n", "path": "examples/android/takepicture/main.py"}]}