Monthly Archives: June 2015

how to download/compile/run(emulator) the source code of android5.0

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo

https://www.googlesource.com/new-password

repo init -u https://android.googlesource.com/platform/manifest/ -b android-5.0.1_r1

repo sync
——-for auto restart when repo sync fail—
#!/bin/bash
FAIL_COUNTS=0
echo “begin to repo sync”
repo sync -f -j4

while [ $? -ne 0 ]; do
((FAIL_COUNTS++))
echo “repo sync fail $FAIL_COUNTS times”
sleep 3
echo “repo sync retry”
repo sync -f -j4
#if [ $FAIL_COUNTS -ge 4 ]; then
#        break;
#    fi
done

echo “repo sync faild $FAIL_COUNTS times”
————-

source build/envsetup.sh

lunch //select the target  aosp_arm-eng

make -j8
—–start the emulator———
emulator -partition-size 1024

 | 509,166 views | 8,339 comments | 0 flags | 

Java jni invoke process under android5.0

android_webview_native_webview_native_gyp.a

external/chromium_org/android_webview/Android.mk(responsible for the java compile)
JNI_Invoke process
external/chromium_org/android_webview/lib/main/webview_entry_point.cc
	JNI_OnLoad
		->base::android::RegisterLibraryLoaderEntryHook
		->content::EnsureJniRegistered
		->RegisterNativeMethods
		->android_webview::RegisterJni
			->android_webview/native/android_webview_jni_registrar.cc
				->RegisterNativeMethods
				->android_webview/native/aw_contents.cc
					->RegisterNativesImpl[AwContents_jni.h]
					->
		->base::android::InitReplacementClassLoader
		->content::SetContentMainDelegate
		->url::Initialize
external/chromium_org/GypAndroid.linux-arm.mk
	[
		AwContents.java
		{
			// Return true if the GeolocationPermissionAPI should be used.
			@CalledByNative
			private boolean useLegacyGeolocationPermissionAPI() {
			    // Always return true since we are not ready to swap the geolocation yet.
			    // TODO: If we decide not to migrate tarm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)he geolocation, there are some unreachable
			    // code need to remove. http://crbug.com/396184.
			    return true;
			}
			private static native long nativeInit(AwBrowserContext browserContext);
		}
		//--------------------------------------------
		aw_contents.cc
		{
			static jlong Init(JNIEnv* env, jclass, jobject browser_context) {
			  // TODO(joth): Use |browser_context| to get the native BrowserContext, rather
			  // than hard-code the default instance lookup here.
			  scoped_ptr<WebContents> web_contents(content::WebContents::Create(
			      content::WebContents::CreateParams(AwBrowserContext::GetDefault())));
			  // Return an 'uninitialized' instance; most work is deferred until the
			  // subsequent SetJavaPeers() call.
			  return reinterpret_cast<intptr_t>(new AwContents(web_contents.Pass()));
			}
			//====================================
			void AwContents::RequestGeolocationPermission(
			    const GURL& origin,
			    const base::Callback<void(bool)>& callback) {
			  JNIEnv* env = AttachCurrentThread();
			  ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
			  if (obj.is_null())
			    return;

			  if (Java_AwContents_useLegacyGeolocarm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)ationPermissionAPI(env, obj.obj())) {
			    ShowGeolocationPrompt(origin, callback);
			    return;
			  }
			  permission_request_handler_->SendRequest(
			      scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest(
				  origin, AwPermissionRequest::Geolocation, callback)));
			}

		}
		//--------------------------------------------
		AwContents_jni.h
		{
		extern "C" {
			static jlong Init(JNIEnv* env, jclass jcaller,
			    jobject browserContext);

			__attribute__((visibility("default")))
			jlong
			    Java_com_android_org_chromium_android_1webview_AwContents_nativeInit(JNIEnv*
			    env, jclass jcaller,
			    jobject browserContext) {arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
			  return Init(env, jcaller, browserContext);
			}
			//==================================================//
			static base::subtle::AtomicWord g_AwContents_useLegacyGeolocationPermissionAPI =
			    0;
			static jboolean Java_AwContents_useLegacyGeolocationPermissionAPI(JNIEnv* env,
			    jobject obj) {
			  /* Must call RegisterNativesImpl()  */
			  CHECK_CLAZZ(env, obj,
			      AwContents_clazz(env), false);
			  jmethodID method_id =
			      base::android::MethodID::LazyGet<
			      base::android::MethodID::TYPE_INSTANCE>(
			      env, AwContents_clazz(env),
			      "useLegacyGeolocationPermissionAPI",

			"("
			")"
			"Z",
			      &g_AwContents_useLegacyGeolocationPermissionAPI);

			  jboolean ret =
			      env->CallBooleanMethod(obj,arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
				  method_id);
			  jni_generator::CheckException(env);
			  return ret;
			}
			//==================================
			static bool RegisterNativesImpl(JNIEnv* env) {
			//??????????????????should invoke env->RegisterNatives
			  return true;
			}

		}
		}
	]
	base/android/jni_generator/jni_generator.py
	../../base/android/jni_generator/jni_generator.py 
		--input_file ../java/src/org/chromium/android_webview/AwContents.java 
		--output_dir "/home/leliang/work/android/sourcecode/out/target/product/generic/obj/GYP/shared_intermediates/android_webview/jni" 
		--includes base/android/jni_generator/jni_generator_helper.h 
		--optimize_generation 0       
		--jarjar ../../android_webview/build/jarjar-rules.txt 
		--ptr_type long --native_exports
	out/target/product/generic/obj/GYP/shared_intermediates/android_webview/jni
		[dynamic generate callback&registar native]
		android_webview_jni_registrar.cc
===============================================================================================
GYP_HOST_MULTILIB = 32
GYP_HOST_VAR_PREFIX = 2ND_
====external/chromium_org/GypAndroid.linux-arm.mk===============================
arm-linux-androideabi-objdump -tT libwebviewchromium.so | grep Java_com_android_org_chromium_android_1webview_AwContents_nativeInit
001d2834 g    DF .text	000000ec Java_com_android_org_chromium_android_1webview_AwContents_nativeInit

refer the autogenerated xxx_jni.h to create the interface(c++ -> native, native -> c++)
=========================

https://chromium.googlesource.com/android_tools/+/master/ndk/sources/android/crazy_linker/README.TXT

The first time you call a native method like:
    'mypackage.MyClass.myNativeMethod()'
  The VM will look into existing native libraries with dlsym() for a
  function symbol named like:
    Java_mypackage_MyClass_myNativeMethod

 

 | 129,739 views | 1,031 comments | 0 flags |