jni-type-conversion
What it does
This skill helps your AI simplify code that passes data between Java and C++ on Android. It is for developers who maintain JNI bridge code.
When to use it
- ✓When you want to remove manual string or object conversion code between Java and C++.
- ✓When a Java method with @NativeMethods or @CalledByNative takes a type that is converted by hand in C++.
- ✓When you need to check whether a type already has a @JniType conversion defined.
Skill link
https://github.com/chromium/chromium/blob/main/agents/skills/jni-type-conversion/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Can you replace the manual string conversion in my Java native method with a @JniType annotation?”
5 new skills a week. 1 minute to read.
How it works
The AI finds JNI methods that convert data by hand, checks whether a @JniType conversion already exists for that type, and then updates the Java and C++ code to use the annotation.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
JNI Type Conversion
This skill guides the process of replacing explicit JNI conversion logic (like
ConvertJavaStringToUTF8) with @JniType annotations in Java and corresponding
native types in C++.
You must first read the prerequisite skill:
//third_party/jni_zero/skills/jni-zero.
Workflow
- Identify Candidates: Look for JNI methods (annotated with
@NativeMethodsor@CalledByNative) that take or return types that are currently being explicitly converted in C++.- Tip: Inspect every
JavaRef(jobject,jstring,j*Array, etc.) parameter in the C++ implementation. Any parameter that is immediately run through a conversion/unwrapping function (such ascontent::WebContents::FromJavaWebContents(...),Profile::FromJavaObject(...),url::GURLAndroid::ToNativeGURL(...),TabAndroid::GetNativeTab(...),ConvertJavaStringToUTF8(...), etc.) is a prime candidate for@JniType.
- Tip: Inspect every
- Discovery (CRITICAL): To see if a type already has a
@JniTypeconversion defined, search the codebase forFromJniTypeorToJniTypedefinitions for that C++ type:
If a conversion exists, note the header file where it is defined; you will need to include it from any C++ files that require the conversion.rg -g "*.h" "\binline .*(From|To)JniType" - Common
@JniTypeTypes & C++ Conversions:std::string/std::u16string(base/android/jni_string.h) <-ConvertJavaStringToUTF8,ConvertJavaStringToUTF16,ConvertUTF8ToJavaString,ConvertUTF16ToJavaStringstd::vector<T>/std::optional<T>(third_party/jni_zero/default_conversions.h) <-JavaIntArrayToIntVector,JavaLongArrayToInt64Vector,AppendJavaStringArrayToStringVector,ToJavaArrayOfStrings, etc.base::OnceClosure/base::OnceCallback<...>/base::RepeatingCallback<...>(base/android/callback_android.h) <-RunObjectCallbackAndroid,RunBooleanCallbackAndroid,RunIntCallbackAndroid, etc.content::WebContents*(content/public/browser/web_contents.h) <-content::WebContents::FromJavaWebContents,GetJavaWebContentscontent::RenderFrameHost*(content/public/browser/render_frame_host.h) <-content::RenderFrameHost::FromJavaRenderFrameHost,GetJavaRenderFrameHostProfile*(chrome/browser/profiles/profile.h) <-Profile::FromJavaObject,GetJavaObjectTabAndroid*(chrome/browser/android/tab_android.h) <-TabAndroid::GetNativeTab,GetJavaObjectui::WindowAndroid*(ui/android/window_android.h) <-ui::WindowAndroid::FromJavaWindowAndroid,GetJavaObjectGURL(url/android/gurl_android.h) <-url::GURLAndroid::ToNativeGURL,url::GURLAndroid::FromNativeGURLurl::Origin(url/origin.h) <-url::Origin::FromJavaObject,ToJavaObjectPrefService*(components/prefs/android/pref_service_android.h) <-PrefServiceAndroid::FromPrefServiceAndroidsignin::IdentityManager*(components/signin/public/identity_manager/identity_manager.h)base::Token(base/android/token_android.h),base::UnguessableToken(base/android/unguessable_token_android.h),base::Uuidforjava.util.UUID(base/uuid.h)
- Verify Constraints: Do NOT convert if:
- The conversion is conditional (e.g., inside an
ifblock that might skip it). - The conversion happens inside a lambda (e.g.,
TRACE_EVENTmacros). Moving these to@JniTypemakes the conversion eager, which can impact performance.
- The conversion is conditional (e.g., inside an
- Annotate Java:
- Add
@JniType("cpp_type")to the parameter or return type. - Integer Types: References to
intin@JniTypeshould always beint32_t(e.g.,@JniType("std::vector<int32_t>")instead of@JniType("std::vector<int>")). - Collections: Prefer
List<T>over object arrays (T[]) for collection parameters and return types (e.g.,@JniType("std::vector") List<SuggestedTabInfo> suggestedTabsinstead ofSuggestedTabInfo[]), especially when Java passes or stores it as aList(avoidingArrays.asList(...)). @NullableTypes:- For
Stringparameters,@JniType("std::string")automatically converts Javanullto C++"". Prefer this overstd::optional<std::string>unless the C++ logic specifically distinguishes betweennulland empty.
- For
- Add
FAQ
What is JNI?
JNI is the bridge that lets Java code call C++ code on Android. It can be tricky to write by hand.
What does @JniType do?
It is an annotation that tells the tool how to convert a Java type into a C++ type automatically, so less code is needed.
Do I need to read anything before using this skill?
The skill says to read a related jni-zero guide first. Your AI should follow that guide before making changes.
Details
Original description by the author
How to use @JniType annotations for ergonomic JNI. Relevant for Java files that use @NativeMethods or @CalledByNative.
repo: chromium/chromium
Popularity
- GitHub stars
- 25k
- Ranking position
- #10060
- License
- BSD-3-Clause
- Updated
- 11/2/2026
Comments
- …
More skills from this repository
fuzzing
25kHelps your agent write fuzz tests that feed many random inputs into code to find crashes and bugs in C++ code.
gn-deps-debugging
25kHelps your agent fix build errors caused by missing or wrong dependencies in GN build files, without adding broad, unneeded ones.
java-memory-leaks
25kHelps your agent find and fix Java memory leaks in Android apps by reading leak reports from LeakCanary.
loadline
25kHelps your agent run LoadLine benchmarks that measure how fast web pages load on Android and desktop Chrome.
Similar skills
android-clean-architecture
280kMakes your agent organize Android projects efficiently. It structures the code to make maintenance and new feature development easier.
compose-multiplatform-patterns
280kHelps your agent use Compose Multiplatform and Jetpack Compose patterns in KMP projects, covering state, navigation, theming, and performance.
dart-flutter-patterns
280kMakes your agent write code for Dart and Flutter apps. It uses modern patterns to create robust and manageable apps.